I have a requirement to find and extract a number contained within a string.
For example, from these strings:
string test = \"1 test\" string test1 =
\d+ is the regex for an integer number. So
\d+
//System.Text.RegularExpressions.Regex resultString = Regex.Match(subjectString, @"\d+").Value;
returns a string containing the first occurrence of a number in subjectString.
subjectString
Int32.Parse(resultString) will then give you the number.
Int32.Parse(resultString)