Remove parts of strings.

Highlighted
One Star

Remove parts of strings.

Hi,
I have a list of records, and quite a few of them have a suffix(es) at the end in parenthesis. I'd like to remove the suffixes but I"m having trouble as the suffixes can be different, and so can the records before the suffix (i.e. suffixes are of different lengths, and so are the names). So to paraphrase the question is how can I remove everything within parentheses.
e.g.
Input
Name1 (x)
Name2 (y)
Name3 (z) (2z)
Name4
Name5 (x)
Name6 (xy) (z)
Name7 (xyz xyz)
Required Output
Name1
Name2
Name3
Name4
Name5
Name6
the suffixes are can be alphanumerics or words.
What would be the best way to approach this - some kind of stringhandling in the expression builder?
Thanks.
edit: I have also tried tReplace with a wildcard value between parentheses "(*)" but that doesn't seem to work.
One Star

Re: Remove parts of strings.

Hi,
try (for example in a tMap) row.Input.contains("(")? row.Input.substring(0, row.Input.indexOf("(")).replaceAll(" ","") : row.Input.
One Star

Re: Remove parts of strings.

Amany, that worked great thanks.
Just to clarify, I'd like to understand it better (my java isn't too good): it asks if the input contains "(", if it does, replace everything to the right of it (how does the code specify only to delete to the right of the bracket?) with a blank. If it doesn't contain "(" then just leave it how it is.
Thanks again.

What’s New for Talend Spring ’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

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog