on 2010 May 26 9:51 AM
I would like to split a string to an array of strings. So my input string could be "onetwothreefourfive" and and I want to create an output array by splitting the string by a specified length lets say by 3. So my output array should then look like the following.
one
two
thr
eef
our
fiv
e
Could someone maybe provide me with a UDF for this functionality?
Hi Mendez,
Try this:
UDF :Advanced udf for all value in queue
input parameter name = input
for (int i=0;i<input.length;i++) {
for (int j=0; j< input<i>.length();) {
char temp[] = new char[3];
try {
for (int k=0;k<3;k++) {
temp[k]= input<i>.charAt(j);
j++;
}
}
catch (Exception e) {
}
String output = new String (temp);
result.addValue(output);
}
}
Regards
Suraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is there anyone that can helping me here?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try:
1.
String x = "onetwothreefourfiv"; -- input
int xlen = x.length();
int outlen = xlen/3;
String[] outs = new String [outlen+1];
int i = 0;
for(int p = 0; p<xlen; p = p +3){
if(p<xlen-3){
int end = p+3;
outs<i> = x.substring(p, end);
i++;
}
else{
outs<i> = x.substring(p);
}
}
for(int t = 0; t<outs.length; t++){
if(outs[t] != null){
resultSet.addValue( outs[t]);
}
}
2.
String x = "onetwothreefourfive"; -- input
int xlen = x.length();
int i = 0;
for(int p = 0; p<xlen; p = p +3){
if(p<xlen-3)
{
int end = p+3;
resultSet.addValue(x.substring(p, end));
i++;
}
else{
resultSet.addValue(x.substring(p));
}
}
User | Count |
---|---|
57 | |
11 | |
7 | |
6 | |
6 | |
6 | |
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.