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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Split long String

please could you help me split a long string more than 50 char from input to 2 columns in output.  the output should be splitted so the columns should make sense.

 

input :

company_name =   "i am new to talend and want to learn,  it great tool for data integration"

 

output:

row1.company_name1 = i am new to talend and want to

row1.Company_Name2 = learn,  it great tool for data integration

 

Regards,

Labels (2)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

Probably due to null values on fields.

Try this:

String[] arr = input_row.col1.split(" ");
output_row.input_row.Company_Name = "";
output_row.input_row.Company_Name1 = "";

for (String word : arr) {
    if ((output_row.Company_Name.length() + word.length() + 1) < 50)
        output_row.Company_Name = output_row.Company_Name + " " + word;
    else
        output_row.Company_Name1 = output_row.Company_Name1 + " " + word;
}
if ((output_row.Company_Name1.length() < 1)
    output_row.Company_Name1 = null;

 

View solution in original post

7 Replies
TRF
Champion II
Champion II

Hi,
Using a tJavaRow and split() method you should be able to do that:

String[] arr = input_row.col1.split(" ");
for (String word : arr) {
if ((output_row.col1.length() + word.length() + 1) < 50)
output_row.col1 = output_row.col1 + " " + word;
else
output_row.col2 = output_row.col2 + " " + word;
}

Can't try cause actually on my mobile, but at least you got the idea.
Hope this helps.
Anonymous
Not applicable
Author

thanks  , not sure what I am doing wrong. for some reason it wont copy the out to excel.0683p000009Lqth.jpg

 

TRF
Champion II
Champion II

The problem is on the tFileExcelInput component which gives you no rows.

Anonymous
Not applicable
Author

fixed the tFileExcelInput , but still below error.

 

 

not sure if tjavarow is in right place and the code in it.

input row column name is "input_row.Company_Name" I want to split it to "output_row.Company_Name" and "output_row.Company_Name1"

output_row.Company_Name can have max 50 char.

 

0683p000009Lqvx.jpg

 

TRF
Champion II
Champion II

Probably due to null values on fields.

Try this:

String[] arr = input_row.col1.split(" ");
output_row.input_row.Company_Name = "";
output_row.input_row.Company_Name1 = "";

for (String word : arr) {
    if ((output_row.Company_Name.length() + word.length() + 1) < 50)
        output_row.Company_Name = output_row.Company_Name + " " + word;
    else
        output_row.Company_Name1 = output_row.Company_Name1 + " " + word;
}
if ((output_row.Company_Name1.length() < 1)
    output_row.Company_Name1 = null;

 

Anonymous
Not applicable
Author

perfect works fine.

TRF
Champion II
Champion II

Great!