some basic string manipulation stuff
I am writing some code in C#, in which part of what I am doing requires that I go through a string and find the first character that is not a numeral.
In C++ I could do this quite simply with the string class's find_first_not_of function. In C#, I don't see any equivalent. There is IndexOf, IndexOfAny, LastIndexOf, and LastIndexOfAny, but those obviously aren't what I am looking for.
So right now I am resorting to this:
You might ask: "You are obviously extracting a numeric value (based on your variable naming mechanism), why not just use the LastIndexOfAny method, and pass it a character array of all numeric characters?" My answer: "The user could input numeric characters somewhere later in the string. Hence it wouldn't work."
string numericValue = string.Empty;
for (int i = 0; i < userInput.Length && !Char.IsLetter(userInput[i]); i++)
numericValue += userInput[i].ToString();