welp, regex change did not work
This commit is contained in:
parent
dac6f4a0c5
commit
a6cf619f00
@ -19,17 +19,31 @@
|
|||||||
|
|
||||||
private int GetValueFromLine(string line)
|
private int GetValueFromLine(string line)
|
||||||
{
|
{
|
||||||
// get all the items
|
MatchCollection matchCollection = Regex.Matches(line, @"(\d)");
|
||||||
List<Match> matches = Regex.Matches(line, @"(\d|one|two|three|four|five|six|seven|eight|nine)").OrderBy(x => x.Index).ToList();
|
List<Match> captures = matchCollection.ToList();
|
||||||
|
|
||||||
|
// replace the text with numbers
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(one)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(two)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(three)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(four)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(five)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(six)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(seven)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(eight)"));
|
||||||
|
captures.AddRange(Regex.Matches(line, @"(nine)"));
|
||||||
|
|
||||||
|
captures = captures.OrderBy(x => x.Index).ToList();
|
||||||
|
|
||||||
// merge first and last index as one
|
// merge first and last index as one
|
||||||
string values = GetStringAsNumber(matches[0].Value) + GetStringAsNumber(matches[^1].Value);
|
string values = GetStringAsNumber(captures.First().Value) + GetStringAsNumber(captures.Last().Value);
|
||||||
// make an int
|
// make an int
|
||||||
return int.Parse(values);
|
return int.Parse(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetStringAsNumber(string value)
|
private string GetStringAsNumber(string value)
|
||||||
{
|
{
|
||||||
switch (value)
|
switch(value)
|
||||||
{
|
{
|
||||||
case "one":
|
case "one":
|
||||||
case "1":
|
case "1":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user