cancel
Showing results for 
Search instead for 
Did you mean: 

Trimming functionality in UDF

Former Member
0 Kudos

Hi all,

Can anyone give me UDF code for trimming eaither side.........

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi sirijna,

if your requirement is like trimming left and right side of the field then.......you can go through the thread...........where gabriel gave the exact code for this type of requirement.........

function leftjustify(String a, Container container)

{

String r="";

for(int i=0;i < a.length();i++)

{

if (a.charAt(i) != ' ' )

{

r = r + a.substring(i);

break;

}

}

return r;

}

function rightjustify(String a, Container container)

{

String r="";

for(int i=0;i<a.length();i++)

{

if (a.charAt(i) == ' ')

{

r=a.substring(0,i);

break;

}

}

return r;

}

Thanks,

Madhu

Answers (3)

Answers (3)

former_member193376
Active Contributor
0 Kudos

Hi

You dont require to write a UDF , its the same case use TRIM standard function in both scenarios (right trim and left trim)because it works perfect.

E.X:

" 1234" --> TRIM --> "1234"

"1234 " --> TRIM ---> "1234"

But still if you need to write the UDF then below is the code:

UDF

function leftjustify(String a, Container container)

{

String r="";

for(int i=0;i < a.length();i++)

{

if (a.charAt(i) != ' ' )

{

r = r + a.substring(i);

break;

}

}

return r;

}

function rightjustify(String a, Container container)

{

String r="";

for(int i=0;i<a.length();i++)

{

if (a.charAt(i) == ' ')

{

r=a.substring(0,i);

break;

}

}

return r;

}

Hope this helps

Thanks

Saiyog

Please update your thread if any issues or close the thread and reward points;

Former Member
0 Kudos

Hi,

We have trim function in the text function type , it removes left sede and right side white spacess.

If you want java code check the below link

http://www.java.happycodings.com/Core_Java/code39.html

GabrielSagaya
Active Contributor
0 Kudos

There is no left trim and right trim function in JAVA

trim() function will alone trim all left and right whitespaces..

String str = " dsfdsf ";

String trimmedStr = str.trim();

System.out.println(str);

str=>dsfdsf with no space on left / right.

Here is your UDF

a->myudf->targetfield

function myudf (String a, Container container)

{

a=a.trim();

return a;

}

Apart from that in Graphical mapping contains trim() which can be directly used.

see my reply on the thread