on 01-12-2017 5:09 AM
Hi All,
Can you please help me with UDF to remove leading zeros,trailing zeros and in between spaces of string.
e.g input string:-0012A45 89 4500
output string:-12A458945
Please help
Regards
Mahesh
Thank you Anoop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
These bunch of java codes must be suite your requirement:-
String output = input.replaceAll(" ", "");
output = output.trim().replaceFirst("^0+(?!$)", "");
output = new StringBuffer(output).reverse().toString();
output = output.trim().replaceFirst("^0+(?!$)", "");
output = new StringBuffer(output).reverse().toString();
return output;
Regards,
Anoop Kumar Rai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh,
If you want to remove leading and trailing zeros (and save any zeros inside your string) then your code could be like below:
// remove leading zeros
while(input.startsWith("0")) {
input = input.substring(1, input.length());
}
// remove trailing zeros
while(input.endsWith("0")) {
input = input.substring(0, input.length() - 1);
}
// remove spaces
input = input.replaceAll("\\s","");
return input;
Regards,
Andrzej Filusz
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Anoop.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Replace all will replace all zeros.:)
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.