Possible Duplicate:
Removing leading zeroes from a string
I need to remove 0 from the beginning of a string and prevent leading 0s when user input the number, how can I do it?
For example:
user input: 000090
display: 90
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One approach is to use an
NSScanner:At this point
remainderis equal to@"90".Equivalently, one could replace the lines
with
to scan past all the zeros rather than to scan until the first non-zero number.
One drawback of this approach is that if the original string is
@"000000000", the resulting string will be empty.