cancel
Showing results for 
Search instead for 
Did you mean: 

Java Userdefined function please

Former Member
0 Kudos

Hi ,

I am required to create a Java user defined function which splits a string into various strings based on a delimiter .

My input string is

<UNH02-MessageIdentifier>INVOIC:D:93A:UN:EDIT30'</UNH02-MessageIdentifier>

I need it as

<field1>Invoic</field1>

<field2>D</field2>

.....

so on.

Did somebody already did it? if so can you point to that user defined function please.

Thank you

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks a lot Varun I am able to achieve what i wanted .

former_member192892
Active Contributor
0 Kudos

hi sudhir,

In your UDF do this

String[] delimitedArr = MessageIdentifier.split(":")

Now based on your target field return either delimitedArr [0] or delimitedArr [1]

Former Member
0 Kudos

Hi Varun

Thanks for your quick response and logic of the UDF . Since i want to make the UDF as a generic one which could be used on any string. I think i can pass on the

delimitedArr [0] or delimitedArr [1] as a constant or an argument at runtime to select the required splited string.

It would be great if you can give me the complete code for the UDF as i have never wrote an UDF yet.

Thanks a lot in advance

former_member192892
Active Contributor
0 Kudos

Hmm, exactly. You can use an extra argument which'll tell you which field this has to be mapped to.

the full code is

function(String outFieldName, String sourceTag, Container container)

{

String output = "";

String [] delimiterArr = sourceTag.split(":");

if(outFieldName.equalsIgnoreCase("field1"))

{

output = delimiterArr[0];

}

else if(outFieldName.equalsIgnoreCase("field2"))}

{

output = delimiterArr[1];

}

return output;

///////////////

Please use as many if else you need to