on 02-05-2009 4:19 PM
Hi experts,
i am having trouble designing an UDF to replace 0 with spaces until an alpha carater is reached. to be more precise :
I have for example as input '000S9002', I would like to have as output ' S9002' (3 white spaces before S)
other example : '0000P128900' => ' P128900'.(4 white spaces before P)
I would like to replace all the zeros before the alpha caracter with spaces.
So far I made :
public String test(String val,Container container){
String result = " ";
val = val.trim();
try{
for (int i=0;i<val.length();i++){
if (val.substring(i).startsWith("0")){
}
else{
result = result + val.substring(i, val.length());
i = val.length();
}
}
}catch(Exception e){
e.printStackTrace();
}
return result;
}
}
So far I can manage to add only one space instead of all the zeros.
'0000P128900' => ' P128900'. (only 1 white space before P instead of 4)
Any help would be greatly appreciated.
Kind regards,
Jamal
Edited by: ba_da_boom on Feb 5, 2009 5:19 PM
Hi,
I guess all you need is to insert another for loop inside of the else statement:
> else{
> result = result + val.substring(i, val.length());
> for (int index = 1; index < i; index++) {
> result = " " + result;
> }
> i = val.length();
> }
index = 1, because you already added one space.
Hope it works.
Regards
Patrick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Patrick, always there when I need help )
THANKS again
Kindly yours,
Jamal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.