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", "");

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.