0

I have input file like -

101 | This is split example

I want to this string "This is split example" into multiple rows.

1st 10 rows in 1st row 2nd 10 rows in 2 row and so on

Output file as like -

101 | This is sp 101 | lit exampl 101 | e

Using Talend how to split this?

2 Answers2

0

I'd use a tJavaFlex and something like:

   String myString = "This is split example"; //Basically something from outside
   do { 
//this is the main part:
    if(myString.length() > 10) {
       System.out.println(myString.substring(0,10));
       myString = myString.substring(10);
    } else {
      System.out.println(myString);
      myString = "";
    }
//this is the end part
   } while(myString.length() != 0);

of course instead of printing you'd like to assign it to an output (row2.data) but you get the idea.

Balazs Gunics
  • 2,017
  • 2
  • 17
  • 24
0

Another way to do it:

enter image description here

tJava

output_row.id = input_row.id; output_row.StringToSplit= input_row.StringToSplit.replaceAll(".{10}(?!$)", "$0;");

then in tNormalise

Normalise column StringToSplit with separator ;

Derek Pollard
  • 6,953
  • 6
  • 39
  • 59