Skip to Content
avatar image
Former Member

Regarding the Mapping Requirment ...!

Hi ,

I have an requirement below is the logic

"send only the substring before the u2018|u2019 delimiter, exclude the rest."

according to the above logic ... if the Input value is given as "ABCDE|FGH"

then my Output result should be "ABCDE" .

Let me know how can i achive using graphical mapping .

Regards,

Aziz khan.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Mar 10, 2011 at 02:49 PM

    Just one line UDF.... That's it.

    Code snippet

    public String splitString(var1, container){
    
    return var1.substring(0,var1.indexOf("|"));
    
    }

    Map source field -> splitString --> target field

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 10, 2011 at 01:55 PM

    Hi AZIZ,

    In your mapping you can use function substring, if you double click on substring it will ask you the starting position --in your case you give it as "0" .

    and for number iof charecters give as "4".then you would be ab;le to generate output accordingly.

    Cheers!!!

    Naveen.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 10, 2011 at 02:00 PM

    use the standar function indexOf and define the character | later create a UDF passing the string and the indexOF value

    OR you should create a UDF ussing the java function Split

    For Example

    public static void main(String args[]) throws Exception{

    String testString = "Real|How|To";

    String result[] = testString.split("|");

    return result[0];

    }

    }

    Rgads

    RodrigoP-.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 10, 2011 at 02:02 PM

    Hi Aziz,

    If String is a fixed length you can use the below code... as UDF.

    Suppose if the string length is 12 characters and if u need to stike of the last 4 characters u can use the below code:

    public String stripFunction(String a,Container container){

    if(a.length() == 12)

    {

    a = a.substring(0,8);

    }

    return a;

    If its not a fixed length then please let me know.

    Thanks,

    Amar.

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 10, 2011 at 02:16 PM

    Hi,

    Chk this:

    Context : Single value, Input will be "a"

    //write your code here

    String b[] = a.split("|");

    return b[0];

    Thanks

    Amit

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      //write your code here

      String key_value1;

      key_value1 = "";

      String[] arr =object_key[0].split("
      |");

      for (int i = 0; i < arr.length; i++) {

      if (i == 0) {

      key_value1 = arr<i>;

      }

      }

      result.addValue((String)key_value1);