Split string and find index

Highlighted
Six Stars

Split string and find index

hi, I have two fields (field1 and field2). field1 is of the type "800; 805; 116; 809; 804; 830; 346; 345; 890; 881; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0" while field2 is of the type "1; 0; 215; 0; 0; 1; 2; 66; 5; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0". I would need to extract from field2 the value corresponding to the index searched in field1 (eg I look for "800" in field1 and extract "1" from field2, for example I look for "116" in field1 and extract "215" from field2). This I would need to do it within tmap.

I hope I have not made too much confusion ..... :-)
thanks a lot


Accepted Solutions
Nine Stars

Re: Split string and find index

in Tmap buiding expression, use below expression

field2.split(";")[java.util.Arrays.asList(field1.split(";")).indexOf("stringtosearch")]

e.g.
String f1 = "800;801;802;803";
String f2 = "X;Y;Z;G";
f2.split(";")[java.util.Arrays.asList(f1.split(";")).indexOf("801")]
this will return Y
Regards
Abhishek KUMAR
( Please mark the post as resolved if you found your solution )

All Replies
Thirteen Stars

Re: Split string and find index

Hi

 

you can do this thru Java code, and if you want to do this with build components:

  • use tNormalize for split row into many rows
  • add row number to the flow - sequence
  • join in tMap by row number

 

regards, Vlad

-----------
Nine Stars

Re: Split string and find index

in Tmap buiding expression, use below expression

field2.split(";")[java.util.Arrays.asList(field1.split(";")).indexOf("stringtosearch")]

e.g.
String f1 = "800;801;802;803";
String f2 = "X;Y;Z;G";
f2.split(";")[java.util.Arrays.asList(f1.split(";")).indexOf("801")]
this will return Y
Regards
Abhishek KUMAR
( Please mark the post as resolved if you found your solution )
Six Stars

Re: Split string and find index

thank you :-)

Cloud Free Trial

Try Talend Cloud free for 30 days.

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.