cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping - Substring Values

tharaka_fernando
Contributor
0 Kudos

Dear All,

Can you please tell me how to get the last 04 digits of a source field to map to destination field.

Source Field length is dynamic.

I guess that UDF is needed for this.

Accepted Solutions (0)

Answers (4)

Answers (4)

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Fernando,

PFA sample udf, which first finds the length of the string, and extract the last four characters and pass to the output.

I just added some additional logic if the length is less than or equal to 4 then it will pass the input as it is to the output. Based on your requirement, you can keep or remove this part.

Regards

Vishnu

former_member183816
Active Participant
0 Kudos

public String last4digit(String in, Container container) throws StreamTransformationException{

if(in.length()>4)

{

in=in.substring(in.length()-4,in.length());

}

return in;

}

iaki_vila
Active Contributor
0 Kudos

Hi Fernando,

You can develop a dynamic substring UDF like this one:

public String dynamicSubstring(String stringToSub, int begin, int end, Container container) throws StreamTransformationException{

return stringToSub.substring(begin,end);

}

Regards.

azharshaikh
Active Contributor
0 Kudos

Hi,

You can achieve this using UDF in ur MM:

if(var1.length() > 4)

return var1.substring(var1.length()-4,var1.length());

else

return var1;

Hope it helps

Regards,

Azhar

aby_jose
Explorer
0 Kudos

Hi Fernando,

Try the below UDF,