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
5 REPLIES
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.