on 10-22-2009 8:26 PM
Hello,
I have a requirement, where in i have to read a string field (input)
split it at every 255th character and send it out into a target(output)which is unbounded
I have written a UDF , but i guess it gets unbounded(infinite loop),
Can anyone correct me or propose a better code?
thanks,
Hank
String out="";
int length=a[0].length();
int end=254;
int start=0;
for(;start<length;)
{
if((start+end)<length)
{
out=a[0].substring(start,(start+end));
result.addValue(out);
start=end+1;
}
}//end of for
if((start+end)>length&&start<length)
{
out=a[0].substring(start,length);
}
Hi,
In your If loop, after the statement,' start=end+1', add 1 more statement,as
end = start + end.
Now check.
Regards,
Supriya.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have made a change to my code, this got it working...thank u
Others pls see if it is good enough
Hank,
String out="";
int length=a[0].length();
int end=255;
int start=0;
for(;start<length;)
{
if((start+end)<length)
{
out=a[0].substring(start,(start+end));
result.addValue(out);
start=start+end;
}
else{
break;
}
}//end of for
if((start+end)>length&&start<length)
{
out=a.substring(start,length);
result.addValue(out);
}
Hi,
check this code
public void UDF(String[] a, ResultList result, Container container) throws StreamTransformationException{
int length=a[0].length();
int start = 0;
int end=255;
String res="";
if(length<255)
result.addValue(res);
else
{
while(length>255)
{
res= a[0].substring(start, end);
length=length -255;
start=end+1;
end=end+255;
result.addValue(res);
}
if(length<255)
result.addValue(res);
}
}
I have checked this code this working fine.
Regards
Ramesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
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.