What is the most efficient way to parse an integer out of a string that contains letters and spaces?
Example: I am passed the following string: "RC 272". I want to retrieve 272 from the string.
I am using C# and .NET 2.0 framework.
What is the most efficient way to parse an integer out of a string that contains letters and spaces?
Example: I am passed the following string: "RC 272". I want to retrieve 272 from the string.
I am using C# and .NET 2.0 framework.
Just for the fun of it, another possibility:
Guys, since it will always be in the format "ABC 123", why not skip the IndexOf step?
EDIT:
If it will always be in that format wouldn't something like the following work where value = "RC 272"?
A simple regex can extract the number, and then you can parse it:
If the string may contain multiple numbers, you could just loop over the matches found using the same Regex:
If it will always be in the format "ABC 123":
Since the format of the string will not change KISS: