0

I have a string of varying length that I am trying to retrieve a number from. The format of the string is always:

"some text lines
FC = 1234
more text here
and so on"

So I know the string of numbers comes after "FC = ", and I know it finishes at the next \n. How can I return this number (which will vary in size) into a new string?

Bennyono
  • 32
  • 5
  • I guess it is time for you to learn Regex :-) https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex?view=netcore-3.1 – Roar S. Aug 17 '20 at 12:11
  • Check this - https://stackoverflow.com/questions/4734116/find-and-extract-a-number-from-a-string – SSD Aug 17 '20 at 12:11

2 Answers2

0

Try the following code snippet:

var str = "some text lines \nFC = 1234\n more text here and so on";
Console.WriteLine(Regex.Match(str, @"\d+\.*\d*").Value);
ScareCrow
  • 497
  • 3
  • 6
0

Thanks to all. Think I managed to find a way with Regex, based on ScareCrow's suggestion:

                    string rgSearch = searchString + @"\d+\.*\d*";
                    FC = Regex.Match(diagnostics, rgSearch).Value;
                    FC = FC.Replace(searchString, ""); //Leaves the number only
Bennyono
  • 32
  • 5