Skip to Content
0

Split string in to many & control the occurence

Apr 11 at 02:48 PM

55

avatar image

Hi Experts,

I have requirement in my mapping to split the input string in to 30 characters each & the occurrence of target field should be controlled by number of strings obtained after splitting. Each split string obtained after splitting to be populated to the corresponding occurrence of target field. Say for example I have input string with 110 characters in the input field so 4 times target field should occur in the target XML with 30,30,30,20 characters in the each occurence of target field.

Thanks,

Ramu.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

7 Answers

Ashish Goel Apr 12 at 12:22 PM
0

Hi Ramu,

Try below UDF its working fine as per your requirement :

public void Split(String[] input, ResultList result, Container container) throws StreamTransformationException{

int count = input[0].length()/30;

int index=30;

int j=1; for(int i=0;i<=count;i++)

{ if(i==count)

result.addValue(input[0].substring((i*index),input[0].length()));

else

result.addValue(input[0].substring(i*index,(30*j)));

j=j+1;

}

Thanks,

Ashish

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Apr 11 at 06:14 PM
0

You can use QUEUE context from the UDF you have for splitting the string.

Share
10 |10000 characters needed characters left characters exceeded
Ramu G Apr 12 at 06:52 AM
0

Hi Experts,

Can someone help on UDF to achieve this?

Thanks,

Ramu.

Share
10 |10000 characters needed characters left characters exceeded
Ramu G Apr 12 at 11:11 AM
0

Hi,

UDF to split input string with length > 70 to that many number of strings with 70 characters each populated to target field. Please help with this UDF.

Thanks,

Ramu.

Share
10 |10000 characters needed characters left characters exceeded
Priyanka Anagani Apr 12 at 11:17 AM
0

Try with the below UDF.

public void splitInputString(String[] inputData, ResultList result, Container container) throws StreamTransformationException{
List<String> strings = new ArrayList<String>();
int index = 0;
while (index < inputData[0].length()) {
strings.add(inputData[0].substring(index, Math.min(index + 30,inputData[0].length())));
index += 30;
}

Iterator<String> itr = strings.iterator();
String currentString = "";

while(itr.hasNext()){
currentString = itr.next();
result.addValue(currentString);
}
}

---Priyanka
Share
10 |10000 characters needed characters left characters exceeded
Peter Karg Apr 12 at 01:21 PM
0

Hi Ramu, I had a similar request and used the fragmentSingleValue from UDFNodePool. Regards

Peter

Share
10 |10000 characters needed characters left characters exceeded
Ambrish Mishra Apr 12 at 08:08 PM
0

I would say take the length of the source string, divide by limit (30 in your case), take the ceil and input into a UDF:

if(count[0] > 0)

for (int i = 0; i < count[0] ; i++)

result.addValue("");

else

result.addSuppress();

Share
10 |10000 characters needed characters left characters exceeded