This might be really simple but i have a service that returns a string that has a number preceded with zeros. The count of zeros is not predictable but i need to extract the number out of the value. The length of the value is also not constant. For ex. 00001234, 002345667, 0000000, 011, 00000987 - in all these values, i need to extract the 1234, 2345667, <no value>, 11, 987.
i have tried doing the below code but it returns the zeros as well:
string.Join( null,System.Text.RegularExpressions.Regex.Split( expr, "[^\\d]" ) );
Can anyone help?
Got my Answer::
I got it using stringObj.TrimStart('0'). But i agree using Int.Parse or Int.TryParse is a better way of handling. Hope this is useful to someone like me!
TrimStarthandle values like-000012? Or will you always have positive integers?