2 parts to a string find/replace issue

Six Stars

2 parts to a string find/replace issue

Hi all,

 

I want to see how I could achieve 2 things.

 

1.  Search and replace a string with blank for everything inside brackets including the brackets. e.g. 

    original text: articulate the interaction of ecology with human society, including policy and legal frameworks for management of biological resources (K, A, E, I)

   New Text: articulate the interaction of ecology with human society, including policy and legal frameworks for management of biological resources

 

2.  With that text inside the brackets, get it and put it into a new field.  This time not including brackets.

 

original

Field 1                                       Field 2

werwerwr (K,A,E,I)

 

original

Field 1                                       Field 2

werwerwr                                    K,A,E,I

 

 

Thanks in advance


Accepted Solutions
Highlighted
Employee

Re: 2 parts to a string find/replace issue

Hi,

 

    Please refer the screen shot below for job output.

image.png

 image.png

 

 

 

The transformations to be used are as below

 

For string first part ->     

row1.input_data.substring(0,row1.input_data.indexOf("(")) 

For string second part ->   

row1.input_data.substring(row1.input_data.indexOf("(")+1,row1.input_data.indexOf(")")) 

If the answer has helped you, could you please mark the topic as resolved? Kudos are also welcome :-)

 

Warm Regards,

 

Nikhil Thampi


All Replies
Highlighted
Employee

Re: 2 parts to a string find/replace issue

Hi,

 

    Please refer the screen shot below for job output.

image.png

 image.png

 

 

 

The transformations to be used are as below

 

For string first part ->     

row1.input_data.substring(0,row1.input_data.indexOf("(")) 

For string second part ->   

row1.input_data.substring(row1.input_data.indexOf("(")+1,row1.input_data.indexOf(")")) 

If the answer has helped you, could you please mark the topic as resolved? Kudos are also welcome :-)

 

Warm Regards,

 

Nikhil Thampi

Six Stars

Re: 2 parts to a string find/replace issue

Thanks Nikhil Thampi, worked a treat.

Six Stars

Re: 2 parts to a string find/replace issue

 Thanks buddy, my requirement similar to this, except having some more conditions like below.

 

1) 6 fields separated by Pipe("|").

2) If the 5th field has values "R", then only 6 field is like "[123:11:xyz:00]", otherwise not.

 

Now, I need to first filter records using the above condition, which I am performing in tmap and separating the required 6 field after removing brackets, but now I want to separate this field(123:11:xyz:00) in the same tmap component having ":" separator and assign values to field1,field2,field3,field4 e.g. field1 would be 123, field2 would be 11, field3 would be xyz and field4 would be 00 and here I am stucking, can someone suggest on how to proceed on this. I only want to use one component( I think tmap should do the task).

I am new to Talend, earlier I was calculating this value in reformat component in ab initio after declaring variable and fetching the fields in vectors.

Thanks in advance.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now