Avatar of MehtaJasmin
Flag for United States of America

asked on 

How to remove leading 0s from String

I have some card number that gets extracted from the record as a fixed size string. The string has always all numbers.

Like for example, my record is:


and I always extract the string from between the  fixed positions. That gives me "00001234000301234"

What is the best API to use to trim the leading zeros and get only "1234000301234". The number of 0s in leading can very in counts anywhere from none to 6.

I see some posting
s.replaceFirst("^0+(?!$)", "")

Open in new window

String card = "00001234000301234";// 
card = Integer.valueOf(card).toString();

Open in new window

But what is the best approach?

Avatar of undefined
Last Comment

8/22/2022 - Mon