cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Udf

Former Member
0 Kudos

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?

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member187339
Active Contributor
0 Kudos

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

Former Member
0 Kudos

is there anyone that can helping me here?

former_member204873
Contributor
0 Kudos

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));

}

}