on 11-07-2006 5:28 PM
Hey guys,
how can i delete a string from a leading substring?
e.g.: "00022521" should become "22521".
thx
Markus
I actually had written a little static class to handle just this. Here is the static class.
public class LeadingZeroRemover {
public static String removeLeadingZeros(String str) {
if (str == null) {
return null;
}
char[] chars = str.toCharArray();
int index = 0;
for (; index < str.length(); index++) {
if (chars[index] != '0') {
break;
}
}
return (index == 0) ? str : str.substring(index);
}
}
Then you can simply use it like this.
<b>LeadingZeroRemover.removeLeadingZeros</b> (soldToNumber.getValue().toString())
Regards,
Rich Heilman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you care ONLY about leading ZEROES than:
new Integer("0000222521").toString();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Markus,
String string1 = "00022521";
String string2 =string1.substring(3,string1.length);
Hope it helps,
Kind Regards,
Sergio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.