Convert string with leading spaces to integer.

I have incoming strings containing 1 or more leading spaces and then digits. What's the easiest way to convert these to integer? I've just found that int(" 4") is zero. I'm surprised at this as I think several other languages that I've used, e.g. C ignore leading whitespace on the conversion. Alright, is there anything for trimming whitespace? I can write my own using String.charAt and .substring, but I'm thinking I there's probably a well-trodden easier way.

Tagged:

Answers

Sign In or Register to comment.