on 08-20-2007 9:50 AM
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
Thanks a lot Varun I am able to achieve what i wanted .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi sudhir,
In your UDF do this
String[] delimitedArr = MessageIdentifier.split(":")
Now based on your target field return either delimitedArr [0] or delimitedArr [1]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.