Split long String

Five Stars

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,


Accepted Solutions
Forteen Stars TRF
Forteen Stars

Re: Split long String

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;

 


TRF

All Replies
Forteen Stars TRF
Forteen Stars

Re: Split long String

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.

TRF
Five Stars

Re: Split long String

thanks TRF , not sure what I am doing wrong. for some reason it wont copy the out to excel.Capture.JPG

 

Forteen Stars TRF
Forteen Stars

Re: Split long String

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


TRF
Five Stars

Re: Split long String

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.

 

Capture.JPG

 

Forteen Stars TRF
Forteen Stars

Re: Split long String

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;

 


TRF
Five Stars

Re: Split long String

perfect works fine.

Forteen Stars TRF
Forteen Stars

Re: Split long String

Great!


TRF

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.