on 04-11-2018 3:48 PM
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.
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ramu, I had a similar request and used the fragmentSingleValue from UDFNodePool. Regards
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Experts,
Can someone help on UDF to achieve this?
Thanks,
Ramu.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use QUEUE context from the UDF you have for splitting the string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.