Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

split input_row with tJavaRow having also null values

Hi @all
Want to split Names in a table to an output table:
i. e.
id Name
1 Tick
2 Trick
3 Tom (Jerry)
4 Goofy
5 Mickey (Mini)
and so on..
want to split to an output table with id, Name, Image
id Name Image
1 Tick Null
2 Trick Null
3 Tom Jerry
4 Goofy Null
5 Mickey Mini

i´ve got some problems within the code, i think it´s a problem because of the string split
String klammerAuf = "\\(";
String klammerZu = "\\)";
//String leerSchritt = " ";
String container;
container = "Null";
int k = input_row.Name.indexOf(klammerAuf);
int l = input_row.Name.indexOf(klammerZu);
//int m = input_row.Name.indexOf(leerSchritt);
if (k > 0 && l > 0)
{
System.out.println("l" + l);
System.out.println("k" + k);
output_row.Name = input_row.Name.split(klammerAuf); //or maybe split(klammerZu)
output_row.Name = input_row.Name.split(klammerAuf); //or maybe split(klammerZu)
}

if (k < 0 && l < 0)
{
output_row.Name = input_row.Name;
output_row.Image = container;
}
output_row.id = input_row.id;
--------------------------------
The above denoted code will output:
id Name Image
1 Tick Null
2 Trick Null
3 Tom (Jerry) Null
4 Goofy Null
5 Mickey (Mini) Null
..so... it doesn´t split...
why?? where am i wrong?? it doesn´t even print out l and k, so it already has trouble with the first if-loop. i switched the code countless times >> array out of bounds exception 1, or maybe i will get a problem regex pattern when i draw off the backslashes in klammerAuf and klammerZu
if i switch the code to String klammerAuf ="(Jerry)", just to see, what´s wrong (if i´ve some trouble with the brackets maybe), it looks like
id Name Image
1 Tick Null
2 Trick Null
3 Tom Null
4 Goofy Null
5 Mickey (Mini) Null
so then it already splits Tom (Jerry) but won´t show Jerry in the Image column.

thx for helping me.
nadine
Labels (2)
5 Replies
Anonymous
Not applicable
Author

ps: i want to split at the brackets, not at the explicit names like Jerry, Mini, etc. This is very important because of more Data Sets. I can´t specify all the names.
_AnonymousUser
Specialist III
Specialist III

String.indexOf does not use regex, so it's literally searching for \( instead of ( as you intended.
Anonymous
Not applicable
Author

Hi nadineherborn
Try the following code 0683p000009MACn.png
if(input_row.Name.indexOf("(")!=-1){
output_row.Name = (StringHandling.LEFT(input_row.Name,input_row.Name.indexOf("(")-1));
output_row.Image = (StringHandling.LEFT(
(StringHandling.RIGHT(input_row.Name,input_row.Name.indexOf(")")-input_row.Name.indexOf("("))),
(input_row.Name.indexOf(")")-input_row.Name.indexOf("(")-1)));
}
else{
output_row.Name = input_row.Name;
}

Regards,
Brandon
Anonymous
Not applicable
Author

oh yes, you´re so right! i had a look into the java documentation.. now it´s working! 0683p000009MA9p.png
thank you!!
Anonymous
Not applicable
Author

Hi,
I was wondering if Talend has functionality to compute value of next row depending upon the previous row just like a loop. I have a problem where i want to calculate value of second row = value of first row + 1. But I don't want to do it simultaneously as in tMap because second value should be computed only when first value is updated. To explain better, here is equivalent loop in C that i want to implement in Talend :
for(i=0,i<100,i++)
{
           array(i+1) = array(i) + 1;
}
Is it possible by any way? I tried using tmemorizeRows and tMap but it's not working.
Thanks and regards,
Himani