1

Hello, does anybody know a simple way to strip the leading zeros out of a string?

I have tried

userName.replaceFirst("^0+(?!$)", "");

but cant seem to make it work, any ideas?

Thanks.


correction, this work..

userName = userName.replace("0", "");

Edited by brynFlew: n/a

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by Ezzaral
1

That will remove all zeros though, regardless of position. Is that what you intend? replaceAll("^0*", "") will remove just the leading ones.

Edited by Ezzaral: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.