aspose file tools*
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trim Characters from String....Help!" Watch "Trim Characters from String....Help!" New topic
Author

Trim Characters from String....Help!

Jennifer Johnson
Greenhorn

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!
Jennifer


Jen
James Swan
Ranch Hand

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

Joined: May 10, 2001
Posts: 3244
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
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
Thank you to everyone for replying! You've all helped me so much!
Jennifer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trim Characters from String....Help!