File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Trim Characters from String....Help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trim Characters from String....Help!" Watch "Trim Characters from String....Help!" New topic

Trim Characters from String....Help!

Jennifer Johnson

Joined: Oct 27, 2001
Posts: 7
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!

James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Try this for starters:
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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.

Ravi Veera
Ranch Hand

Joined: Jun 23, 2001
Posts: 127
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))
Jennifer Johnson

Joined: Oct 27, 2001
Posts: 7
Thank you to everyone for replying! You've all helped me so much!
I agree. Here's the link:
subject: Trim Characters from String....Help!
It's not a secret anymore!