cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding splitting udf

giridhar_vegi
Participant
0 Kudos

Hi Experts ,

               i had requirement where i am getting multiple emails seperated by the delimiter ; so i need to split this based on delimiter i have used the following java code but i am getting the error

Execution type is all values of context

for(int i=0;i<Email;length++)

{

string token[]=Email[i].split(';' )

Email.addValue(token[0]);

Email.addValue(token[1]);

}

Thanks in advance

Giridhar

Accepted Solutions (0)

Answers (3)

Answers (3)

giridhar_vegi
Participant
0 Kudos

the input of email ids will dynamically changes.some time one mail id will be there and sometimes multiple mail ids will be there some times it may be blank. as you said i tried but it works for the fixed no of mail ids.if dynamically changes it is not working

Thanks

Giridhar

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Giridhar,

Can you try this one?

Code:


int len = delim.length();

ArrayList<String> list = new ArrayList<String>();

for(int a=0;a<len;a=a+2){

  list.add(delim.charAt(a)+"");

}

for(int a=0;a<input.length;a++){

  String del = "";

  for(int b=0;b<list.size();b++){

  del = list.get(b).toString();

  if(input[a].indexOf(del)>-1){

  break;

  }

  else{

  del = "";

  }

}

if(del.equals("")){

  result.addValue(input[a]);

}

else{

  String tmp[] = input[a].split(del);

  for(int b=0;b<tmp.length;b++){

  result.addValue(tmp[b]);

  }

}

}

Since this is a parameterized UDF, you have to double click the UDF and input your parameters

Just input your delimiters followed by a space. In the example above, the third delimiter is a space.

Sample input/output:

Limitations: The code provided does not deal with special characters as delimiters e.g ampersand &, pipe |, etc.

Hope this helps,

Mark

praveen_sutra
Active Contributor
0 Kudos

hi Giridhar,

Please mention the error you are getting.

But i think you are going wrong with the code. Please try this and send the error message.

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

{

string token[]=Email[i].split(';' )

Email.addValue(token[0]);

Email.addValue(token[1]);

}

thanks and regards,

Praveen t

Former Member
0 Kudos

Hi

Try this one.

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

{

String token[]=Email[i].split(";");

result.addValue(token[0]);

result.addValue(token[1]);

}

Output:

Thanks,

Indrajit

giridhar_vegi
Participant
0 Kudos

hi indrajit,

what are the functions that i have to use to create the new element based upon the input


Former Member
0 Kudos

Hi

Please tell me your exact reuirement. I will provide you the solution.

Thanks,

Indrajit

giridhar_vegi
Participant
0 Kudos

input:

giridhar@gmail.com;santosh@gmail.com;satish@gmail.com

the input may vary some times only single mailid is present some times there will be 4 mail ids

depends upon the input it needs to generate the target.

i.e case1: im having single mail id

case 2: incase of more than two mailids

case 3 :sometimes it will  be blank on source side

so according to this i want the udf

Thanks

Giridhar

giridhar_vegi
Participant
0 Kudos

i.e i need to split if more email ids are there .i mean it dynamically changes

Thanks
Giridhar

giridhar_vegi
Participant
0 Kudos

i.e i need to split if more email ids are there .i mean it dynamically changes.

Thanks
Giridhar

Former Member
0 Kudos

Hi Giridhar,


Use the UDF given by . Map to your target field.


Source field ---->UDF---->Target field


If you want to change the context of each value (mail id) then use split by value (each value).

Source field ---->UDF---->Split By Value (Each Value) ----> Target field


Regards,

Suhale Shaik.

giridhar_vegi
Participant
0 Kudos

this i have done but it works for the fixed no of input mail ids

Thanks

Giridhar

praveen_sutra
Active Contributor
0 Kudos

hi Giridhar,

Please use this function.

Email will be string type input parameter as shown by Indrajit.

if(Email.length==0)

result.addValue("");

else     {

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

         {

               String token[]=Email[i].split(";");

               for(int j=0;j<token.length;j++)

                    result.addValue(token[j]);

          }

}

giridhar_vegi
Participant
0 Kudos

Thanks Praveen it works but is it possble to split on multiple delimiter for example in one record i am getting the delimiter as ";" and in another record iam getting ",". if it is possible then what the java code i need to insert.

Thanks

Giridhar

praveen_sutra
Active Contributor
0 Kudos

Hi  Giridhar,

yes you can use replace function.

Str.replace(',', ';');


Please try below code it will take care of both the requirement.


if(Email.length==0)

result.addValue("");

else     {

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

         {

               String str = Email[i];

               str.replace(',',';');

               String token[]=str.split(";");

               for(int j=0;j<token.length;j++)

                    result.addValue(token[j]);

          }

}

giridhar_vegi
Participant
0 Kudos

Hi Praveen,

               i have modified the code as you said but it is not splitting

i have given the outut as giridhar@gmail.com,santosh@gmail.com and the output has came as like input with out splitting.

Thanks

Giridhar.

Former Member
0 Kudos

Hi

Try this code

if(Email.length==0)

result.addValue("");

else     {

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

         {

               String str = Email[i];

              

               if ( str.indexOf(";") != -1 )

              

               {

               String token1[]=str.split(";");

               for(int j=0;j<token1.length;j++)

                    result.addValue(token1[j]);

               }

             

              if ( str.indexOf(",") != -1 )

              

               {

               String token2[]=str.split(",");

               for(int k=0;k<token2.length;k++)

                    result.addValue(token2[k]);

               }

          }

}

praveen_sutra
Active Contributor
0 Kudos

Hi Giridhar,

Please try this.. there was small code missing.

if(Email.length==0)

result.addValue("");

else     {

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

         {

               String str = Email[i];

               str = str.replace(',',';');

               String token[]=str.split(";");

               for(int j=0;j<token.length;j++)

                    result.addValue(token[j]);

          }

}

Hope this helps.

thanks and regards,

Praveen T