cancel
Showing results for 
Search instead for 
Did you mean: 

Removing leading zeros and leading blank spaces from an input field

Former Member
0 Kudos

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 .

Accepted Solutions (1)

Accepted Solutions (1)

former_member184619
Active Contributor
0 Kudos

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

Answers (9)

Answers (9)

Former Member
0 Kudos

hi Shweta ,

Thanks for ur reply .

This worked . Only difference was i first applied the UDF and then the TRIM function .

Regards ,

Loveena.

former_member181985
Active Contributor
0 Kudos

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;

markangelo_dihiansan
Active Contributor
0 Kudos

Solution already posted by Singh...

Edited by: Mark Dihiansan on Apr 22, 2009 9:44 AM

Former Member
0 Kudos

HI,

Use standard Function trim(), Under text functions to remove the leading space.

Regards,

Shweta.

Shabarish_Nair
Active Contributor
0 Kudos

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

madanmohan_agrawal
Contributor
0 Kudos

Hi Loveena ,

Use the following code in your UDF..

int i = Integer.parseInt(str);
String str1 = Integer.toString(i);
return str1;

regards,

Madan Agrawal

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.....

Former Member
0 Kudos

Hi,

I think standard functions should server your purpose.... Check under string group.

Regards,

Siddhesh S.Tawate