Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have a csv file:
COL1|COL2|COL3
avant|99999;88888;77777|après
I want to split column 2.
So I did in a JavaRow:
output_row.COL1 = input_row.COL1;
output_row.COL2_1 = StringHandling.TRIM(input_row.COL2).split(";")[0];
output_row.COL2_2 = StringHandling.TRIM(input_row.COL2).split(";")[1];
output_row.COL2_3 = StringHandling.TRIM(input_row.COL2).split(";")[2];
output_row.COL3 = input_row.COL3;
But I have this error: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
it's ok only with
output_row.COL2_1 = StringHandling.TRIM(input_row.COL2).split(";")[0];
I don't understand because I have 3 elements and if I test with
StringHandling.TRIM(input_row.COL2).split(";").length,
it turns out 3 for me...Thanks for your help.
Hello @Simon Thieffry ,
I can't reproduce the issue in my side, could you please provide the whole job execution error log for more investigation? thanks
Best regards
Aiming
Hello,
here is the error log:
Démarrage du Job test à 10:31 04/05/2023.
[statistics] connecting to socket on port 3699
[statistics] connected
Exception in component tJavaRow_1 (test)
java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
at godin.test_0_1.test.tFileInputDelimited_1Process(test.java:1059)
at godin.test_0_1.test.runJobInTOS(test.java:1513)
at godin.test_0_1.test.main(test.java:1351)
[statistics] disconnected
Job test terminé à 10:31 04/05/2023. [Code de sortie = 1]
And more info on the job in the capture.
Thanks.
Simon
Hello,
No, there is no space in my separator, that is semicolon.
But using the code with the intermediate variable it works :
String[] col2Values = StringHandling.TRIM(input_row.COL2).split("; ");
output_row.COL2_1 = col2Values.length >= 1 ? col2Values[0] : "";
output_row.COL2_2 = col2Values.length >= 2 ? col2Values[1] : "";
output_row.COL2_3 = col2Values.length >= 3 ? col2Values[2] : "";
Thanks.
Simon