Split row in multiple rows (new row after x chars)

Not applicable

Split row in multiple rows (new row after x chars)

hello,
i would like to split a row (string) to multiple rows.
i have a string (size 15660 chars or more), and i would like to split it in multiple rows after each 2610 chars. so i can process each sub-string 
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' ===> 
'aaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaa'
Thanks.
i took a look on 'tSplitRow' but it does not do what i wont. (or i didn't understood :-/) 
thanks.
One Star

Re: Split row in multiple rows (new row after x chars)

Hi,
You can use a tSplitRow.
If max input length is known and not to high, use tSplitRow.
In the Columns mapping tab add as many rows as needed.
For exemple:
  row3.longString.substring(0, 2610) 
  row3.longString.substring(2611, 5220)
  and so on
Else, you need a procedural approach using tLoop, tJavaRow, tHashOutput and may be 1 ou 2 global variables.
Hope this helps.
TRF
One Star

Re: Split row in multiple rows (new row after x chars)

Hi,
You can use a tSplitRow.
If max input length is known and not to high, use tSplitRow.
In the Columns mapping tab add as many rows as needed.
For exemple:
  row3.longString.substring(0, 2610) 
  row3.longString.substring(2611, 5220)
  and so on
Else, you need a procedural approach using tLoop, tJavaRow, tHashOutput and may be 1 ou 2 global variables.
Hope this helps.
TRF
Sixteen Stars

Re: Split row in multiple rows (new row after x chars)

This tutorial may help (https://www.rilhia.com/quicktips/quick-tip-row-multiplication). It is not exactly what you want to do, but should give you an idea of how you can achieve the row multiplication. You will see in the tutorial that a number is used to decide how many rows should be returned. You can use the String column value to calculate this in the "Start Code" section of the tJavaFlex.
Like below...
String  stringVal = ((String)globalMap.get("myKey")); //Retrieves the value supplied to the tMap
int len = 2610; //Your String length
int count = (stringVal.length()/len) + (stringVal.length()%len > 0 ? 1 : 0); //Calculate the number of loops
for(int i = 0; i<count; i++){ //Start loops

Then in the "Main Code" do something like this...
if(i==(count-1)){ //If it is the last loop, set the String length as the end of the substring
row2.newColumn = stringVal.substring(len*i,stringVal.length());
}else{ //Otherwise use increments of len
row2.newColumn = stringVal.substring(len*i,(len*i)+len);
}
row2.newColumn1 = i+1; //return loop number (if necessary)

The "End Code"....
} //Close loop

Hope this helps
Not applicable

Re: Split row in multiple rows (new row after x chars)

thanks for yours replies,
I finally used Java, to perform split,
i just wonted to find a talend component that allow to split string after each chars. 
the solution with tloop and then do a split, its graphically nice so others person can understand what i'm doing. but java its fast and cleaner.
thanks.