cancel
Showing results for 
Search instead for 
Did you mean: 

help regarding a scenario

former_member1283182
Participant
0 Kudos

i have a doubt.

for example if my source data has a string of 20 characters length like

<b>

AMERICIANSTANDARDBANK

</b>

So while i transfer the source data to destination i have 2 criteria

- after the 10th character that is the 11th letter should be replaced by letter 'O' and

- the target string should contain only 15 characters, and all the characters after the 15th letter that is from 16th letter on wards should be truncated.

so target should be : AMERICIANS<u>O</u>ANDA

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Satish,

Write UDF //In my udf input parameter is 'a' change accordingly.

String ret="";

if(a.length() >15)

{

ret=a.substring(0,10) "O"a.substring(11,15);

}

else if(a.length() <=10)

{

ret =a;

}

else if(a.length ()==11)

{

ret =a.substring(0,10) +"O";

}

else

{

ret =a.substring(0,10) "O"a.substring(11,a.length());

}

return ""ret"";

Best regards,

raj.

Former Member
0 Kudos

brilliant Raj

former_member1283182
Participant
0 Kudos

raj,

ur awesome da. thankx a lot...

i ll post u more queries as i get them..

justin_santhanam
Active Contributor
0 Kudos

Satish:U r most welcome my friend.

Thnxs Deepak!!!

Best regards,

raj.

Former Member
0 Kudos

Sathish, you should have given 10 points to raj.

By mistake you gave it to deepak, please correct that.

former_member1283182
Participant
0 Kudos

hi pete, thanks a lot for the remainder, by mistake in a hurry i might have given points.

I have corrected, excellent work by you.

regards,

satish.

Answers (1)

Answers (1)

Former Member
0 Kudos

Satish,

If you always have a string of 20 characters from the input then you take a substring from 1 to 10 and then concat with 'o' and then use the UDF to get the value from 11th position to the end and then once again take the substring.

Use this UDF which gets the value from position 11 to the end:

Create a Value UDF with two input parameters. First parameter ‘a’ is used to pass the length and the second parameter ‘b’ is used to send the actual value to the UDF. Now add this code:

int i = Integer.parseInt(a);

String c = b.substring(11,i);

return c;

In mapping you map this two fields to the UDF:

Source>Length>UDF

Source-->UDF

It gets you the value from the 11th position to the end.

Regards,

---Satish