on 01-09-2015 8:26 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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]);
}
}
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.
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]);
}
}
}
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
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.