static void Main(string[] args)
{
string foo = "jason123x40";
char[] foo2 = foo.ToCharArray();
string foo3 = "";
for (int i = 0; i < foo2.Length; i++)
{
int num = 0;
Int32.TryParse(foo2[i].ToString(), out num);
if (num != 0)
{
foo3 += num.ToString();
}
}
Console.WriteLine(foo3);
Console.ReadLine();
}
So lets say I have a string called "john10smith250". The result should be "10250". However I would get "125" instead with my code.
The reason I filtered out the 0 was because I didn't want any non numeric characters to be treated as a zero.
Is there a better way to convert a part of a string into an int?