Skip to Content
avatar image
Former Member

Regarding splitting udf

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Jan 09, 2015 at 08:48 AM

    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


    indra.jpg (34.4 kB)
    indra.jpg (17.5 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Jan 09, 2015 at 08:53 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 09, 2015 at 12:26 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

      test.png (9.1 kB)
      test.png (8.0 kB)
      test.png (10.9 kB)