Remove parts of strings.

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

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads