tMap Check for Numbers

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
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
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"
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.
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
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.

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey

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

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch