I need to trim leading zero's from a string variable, for example: 0000006566. The number of zero's will not always be the same. Can someone help? Thank you in advance! Jennifer
Jen
James Swan
Ranch Hand
Joined: Jun 26, 2001
Posts: 403
posted
0
Try this for starters:
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Jennifer If the string is always going to be an int (it has no characters in it) then Integer.parseInt() will do it for you.
Or a more generic one could be
there is probably even a simpler way, but those were the first two that came to mind, hope it helps.
Dave
Ravi Veera
Ranch Hand
Joined: Jun 23, 2001
Posts: 127
posted
0
Here's a fancy approach if you want to look cool and show off your knowledge of JDK1.4
String stest="000000506505"; while (stest.startsWith("0",0)) { stest=stest.replaceFirst("0",""); stest=stest.trim(); } System.out.println("test="+stest);
Jennifer Johnson
Greenhorn
Joined: Oct 27, 2001
Posts: 7
posted
0
Thank you to everyone for replying! You've all helped me so much! Jennifer
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.