cancel
Showing results for 
Search instead for 
Did you mean: 

Add trailing spaces dep

Former Member
0 Kudos

Hello All,

I need help to write UDF

My requirement is to add trailing spaces the string depnding on the specific String startswith

For example:

Starting charcters Length

HD 55

SH 233

CR 25

So i need to check if the string is starting with specifc Key then chaeck the length and then add spaces.

Can someone please help

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello All,

I have written the below code:

Can someone please help how i can store length for each String and send as output

{

//write your code here

int length = 0;

String val1 = "";

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

{

if(a<i>.startsWith("HD")){

length = a<i>.length();

if (length <= 33)

{

int val = 33 - length;

val1 = Integer.toString(val);

}

}

if(a<i>.startsWith("MA")){

length = a<i>.length();

if (length <= 208)

{

int val = 208 - length;

val1 = Integer.toString(val);

}

}

if(a<i>.startsWith("SH")){

length = a<i>.length();

if (length <= 47)

{

int val = 47 - length;

val1 = Integer.toString(val);

}

}

}

result.addValue(val1);

}

Thanks

maciej_jarecki
Contributor
0 Kudos

Hi,

You would like to receive as result HD and length f.ex. 25 in one field in this case HD 25 ??

if yes

than check your length and use java string function concat val + length and assign it to result.

If no

and you would like to count it and once append it to target filed. UDF and and change context od source parameter of this function. Then loop on context elements and make neccesary operation. after loop append to target filed final length.

Regards

Maciej