Skip to Content
author's profile photo
Former Member

Java Userdefined function please

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Posted on Aug 20, 2007 at 08:54 AM

    hi sudhir,

    In your UDF do this

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

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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • author's profile photo
    Former Member
    Posted on Aug 20, 2007 at 10:28 AM

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

    Add comment
    10|10000 characters needed characters exceeded