cancel
Showing results for 
Search instead for 
Did you mean: 

UDF :Left trim and Right trim

Former Member
0 Kudos

Hey,

I need to do some Left trim and right trim functions. Can anybody share theire experiences with these functions.

If possible provide me the UDF for both.

-S

Accepted Solutions (1)

Accepted Solutions (1)

GabrielSagaya
Active Contributor
0 Kudos

1) left justify

function myudf(String a, Container container)

{

String r="", s="";

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

{

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

r=s+a.charAt(i);

}

return r;

}

2) right justify

function myudf(String a, Container container)

{

String r="";

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

{

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

r=r+a.charAt(i);

}

return r;

}

Former Member
0 Kudos

Sorrry....Now its giving blank value in the output.

-E

GabrielSagaya
Active Contributor
0 Kudos

sorry for the wrong code

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;

}

Former Member
0 Kudos

Thanks Gabriel.............Points rewarded

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

In the standard functions, select TEXT --> trim function, then it will removes white space from the left and right sides.

If you want to write UDF then.

Create UDF(select cache type as Value) and give any argument name.(suppose str).

code

String trimmedStr = str.trim();

return trimmedStr;

Former Member
0 Kudos

You can directly use Trim() functions during graphical mapping.

Its under text functions.

Gaurav Jain

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.

Former Member
0 Kudos

Thanks for the comments...

But I need a left justify and right justify separately on my scenarios;

for Ex: " 12345" ---> I need to do some left justify here

"12345 " ---> I need to do some right justify here

help me out with the UDF.

-S

GabrielSagaya
Active Contributor
0 Kudos

1) left justify

function myudf(String a, Container container)

{

String r="";

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

{

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

r=a.charAt(i);

}

return r;

}

2) right justify

function myudf(String a, Container container)

{

String r="";

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

{

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

r=r+a.charAt(i);

}

return r;

}

Former Member
0 Kudos

I got below errors..when I test the scenario

.java:446: unexpected type required:

variable found : value

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

.java:447: incompatible types found : char

required: java.lang.String

r=a.charAt(i);

^ 2 errors

-E

Former Member
0 Kudos

For left justify you can use

public String Lefttrim(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;

}

Gaurav Jain

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi Esha.

its the same case use TRIM standard function in both scenarios because it works perfect.

E.X: " 1234" --> TRIM --> "1234"

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

there no difference if the spaces are in the rigth of left no UDF is nedded.

thanks

Rodrigo