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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.