on 04-22-2009 8:25 AM
Hi All,
I have an input field which is alphanumeric and i need to remove the leading zeros and blank spaces in it , but intermediate spaces should be kept .
so i used the UDF
String output = input.replaceFirst("^0+","");
return output;
but this code does not remove the leading blank spaces . Can anybody help in modifying this code so that even the leading blank spaces along with leading zeros can be removed .
Regards ,
Loveena .
hi Loveena,
you can use the trim standard function under Text category in standard function for the same:
trim
Removes all white space characters (spaces, tabs, returns) at the start and end of a string.
Sachin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Shweta ,
Thanks for ur reply .
This worked . Only difference was i first applied the UDF and then the TRIM function .
Regards ,
Loveena.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this UDF,
for (int i = 0 ;i < a.length() ; i ++ )
{
if (a.startsWith(" ") || a.startsWith("0") )
{
a = a.substring(1, a.length() );
}
else
break;
}
return a;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Solution already posted by Singh...
Edited by: Mark Dihiansan on Apr 22, 2009 9:44 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
Use standard Function trim(), Under text functions to remove the leading space.
Regards,
Shweta.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
lets say input is a
then
int len = a.length();
for(int i;i< length;i++)
{
if(a.substring(0,1).equals(" ") || a.substring(0,1).equals("0"))
{
a = a.substring(1,len);
}
}
return a;
hope you got the logic so that you can enhance it better
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Loveena ,
Use the following code in your UDF..
int i = Integer.parseInt(str);
String str1 = Integer.toString(i);
return str1;
regards,
Madan Agrawal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use
String output = input.replaceFirst("^[0\' ']+","");
return output;
Or you can use String.Trim() separately if you don't want to use the regular expression.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
please write one more UDF which take the input from thid UDF nad in that remove the leading blank because u have right alogic which will remove the zero only.....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think standard functions should server your purpose.... Check under string group.
Regards,
Siddhesh S.Tawate
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.