tMap Check for Numbers

Highlighted
One Star

tMap Check for Numbers

Hello,
I am creating a map and I need to return a String. The problem is that my data contains numbers at the beginning some times.
So I might have account number = "00114" or "B1487"
How can I tell Talend to trim the zeros at the beginning if its a number.
I have tried something like this but does not work
isNumeric(row3.account_number)? 
Integer.valueOf(row3.account_number).toString():
row3.account_number

Thanks
Highlighted
One Star

Re: tMap Check for Numbers

Hi
After convert row3 to string, you can use replaceAll :
row3.replaceAll("^0+", ""); // Replace all 0 by "" (to the first character different) of 0
Highlighted
One Star

Re: tMap Check for Numbers

Hi,
Thanks for the reply but if will fail if my account is something like "15800" or " B344014"
Highlighted
One Star

Re: tMap Check for Numbers

I have not tested but normally only the 0 placed at the beginning of the string will be replaced, other 0 contained inside the account number will not be replaced.
Highlighted
One Star

Re: tMap Check for Numbers

Hi,
I apologize for my previous answer. The code suggested did work but now it fails when I have more than one consecutive 0 at the beginning. For example: "000125" or "0014587"
Thanks
Highlighted
One Star

Re: tMap Check for Numbers

Hi,
For this i used a tJavaRow which allows me to use Try/Catch blocks of code. Something like this solved my problem.
try{
output_row.account_number =
Integer.valueOf(input_row.account_number).toString();
}catch(NumberFormatException ex){
output_row.account_number=input_row.account_number;
};

uff so much to learn still. But this is fun!! I am loving it Smiley Happy
Thanks for the big help.

2019 GARTNER 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

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog