cancel
Showing results for 
Search instead for 
Did you mean: 

Take values before comma

Former Member
0 Kudos

Hi folks

I need help in a context udf : pass arrays

Source field:

Array of values

Sun is bright,Moon shines

Ball is blue,table is brown

If we see there is a comma in source field and we pass an array of source values to a udf

In target i have 2 fields.

I want to extract the values from source before comma and map to the first target field

and the text after comma in the second target field.

Is it achievable in XI and I am not good in writing java udfs.

Help will be appreciated.

Thnx

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

By using IndexOf , Length and Substring function from text you can solve this problem without using UDF.

1) Using IndexOf to check the index of (, or ;).

2) For 1st Target field use Substring, start with 0 and no. of char are (index of (, or - 1).

3) Then check total length of Input value by using Length function.

4) For 2nd target field use Substring start with (index of (, or + 1) and no. of char. are (total length - index of (, or )

Regards,

Rohit.

Former Member
0 Kudos

hi folks

i am actually modifying some udf by adding this part of logic in it. So i need a udf logic for my requirement.

Thnx

former_member214364
Active Contributor
0 Kudos

Hi,

I have prepared word document with UDF code and Mapping screens,If you provide your email ID i can send it through.

Thanks,

Jag

************

Please read the Forum's Rules of Engagement,

i.e.,

[/thread/117188 [original link is broken];

and refrain from using email correspondence as the main objective of the Forums is to share knowledge.

SDN PI/XI Forum Moderator

Former Member
0 Kudos

Hi,

as you have two targets you will have two UDFs ( a is the parameter).

For the first string:

>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));

>if (index > 0) {

>return a.substring(0, index);

>}

>return a;

For the second string:

>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));

>if (index > 0) {

>return a.substring(index + 1, a.length());

>}

>return a;

You could also do it with one UDF if you pass another parameter b that you fill with a constant ( "1" in case of first target and "2" in case of second target).

The UDF looks then like this:

>int index = (a.indexOf(";") > a.indexOf(",")? a.indexOf(";") : a.indexOf(","));

>if (index > 0 && b.equals("1")) {

>return a.substring(0, index);

>}

>if (index > 0 && b.equals("2")) {

>return a.substring(index + 1, a.length());

>}

>return a;

Regards

Patrick

Edited by: Patrick Koehnen on Sep 25, 2008 10:45 AM

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

This is very simple


1. goto initialization section
    under golbal variable make a declaration for string array
    String arr[];


2.  you have to write 2 udf's
      src---->splitsrc1--->tgt1
      src---->splitsrc2--->tgt2

Use cache parameter as context for both UDF


3.  udf-1
  public void splitsrc1(String[] a,ResultList result,Container container)
{
//write your code here
  arr  = a[0].split(",");
result.addValue(arr[0]);
}


4. udf-2
public void splitsrc2(String[] a,ResultList result,Container container)
{
//write your code here
result.addValue(arr[1]);
}

Edited by: malini balasubramaniam on Sep 25, 2008 9:07 AM

former_member518917
Participant
0 Kudos

Hi,

Try this UDF:

here pass value FIRST or SECOND to 2nd parameter of the UDF (FIRST if u want value before comma and SECOND if want value after comma )

getValues(String str[], String position, Container ....){

int i= str.indexOf(",");

if(position.equals("FIRST")){

result.addValue(str.substring(0,i));

}else if(position.equals("SECOND")){

result.addValue(str.substring(i+1, str.length()) );

}

}

former_member214364
Active Contributor
0 Kudos

Hi,

Whats your XI version?

Its possbile with UDF code.

Thanks,

Jag

Former Member
0 Kudos

Hi folks

XI version is XI 3.0

If it is possible ,can someone help me with how to do the java udf for this scenario.

Thanks

former_member214364
Active Contributor
0 Kudos

Hi,

Always do you get 2 strings with sepatator(",") in source field?

Thanks,

Jag

Former Member
0 Kudos

Hi

I get either comma or semi colon ( ,

Thnx