Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
_AnonymousUser
Specialist III
Specialist III

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.
Labels (2)
5 Replies
KELASRI
Contributor
Contributor

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
KELASRI
Contributor
Contributor

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
Anonymous
Not applicable

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
_AnonymousUser
Specialist III
Specialist III
Author

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.
Anonymous
Not applicable

Hi,

I know its too late for a reply. But posting it anyway as it might help someone else facing the similar issue now and going forward. It can be done using tJavaFlex as in one of earlier replies. But it can be done easily using tFileInputPositional and set "" as Row Separator and Pattern as "2610" as follows:

 

0683p000009M5r3.png


It should split a row (string) to multiple rows having 2610 characters in each row. So, it should generate total of 6 rows (15660 / 2610).

Hope this helps !