cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove Space

Former Member
0 Kudos

Hi group,

I have one string with length 15 ,sometimes I am getting this fields with in between sapces and hyphen(-) ,how to remove these spaces and hyphen using JAVA in UDF.

Can any suggest

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Also might want to use the standard function 'trim' to remove leading and trailing blank spaces....

Thanks,

Renjith

Former Member
0 Kudos

Hi Can't use Replace string becuase sometimes I may get spl character (-,space,S,X) only I need to allow the numeric values.

Former Member
0 Kudos

So is what you want some thing like pass all the numeric values in the 15 character long string..is it ?

if yes please use this code in UDF...

int len = input.length();

String output = "";

for(int i = 0; i < len; i++){

if(Character.isDigit(input.charAt(i))){

output+= input.charAt(i);

}

}

return output;

Thanks,

Former Member
0 Kudos

Hi Ranjith,

When I am using this code I am getting only one first digit as output,not getting all the string

Former Member
0 Kudos

could you please post the code...the '}"'s should be at the right places...

i tested this code in a sample mapping here at my end and it works fine...

Thanks,

Renjith

Former Member
0 Kudos

Here I am attaching the code



String b="";
for(j=0; j<a.length; j++)
{

if(Character.isDigit(a[j].charAt(j)))
b=b+a[j].charAt(j);

}

result.addValue(b);


Former Member
0 Kudos

Hi,

You have to create a simple udf...

When you create the mapping chose "Value" for the cache and not "Context" or "Queue"...

Then use the code exactly as i have given....rename the input value to 'input'.....

Thanks,

Renjith

Former Member
0 Kudos

HI Ranjit,

Thank you

Former Member
0 Kudos

No problem.

Please close the thread if your problem is solved.

Thanks,

Renjith

Former Member
0 Kudos

Hi,

Why do you need a UDF for this ? Can't you use 'replaceString' standard function ?

Thanks,

Renjith

Former Member
0 Kudos

Hi,

just create a UDF with a String argument a:

int i = a.length();

String b="";

Char c;

for (int j=0; j<i; j++)

{

c=a.charAt(j);

if (c!=' ' && c!='-')

b=b+c;

}

return b;

Thanks,

Rajeev Gupta