Add leading zero's

Highlighted
One Star

Add leading zero's

I have a text file containing a column "ID". Please see example below. The ID should be an integer with length 3. Now the problem is that some records have values which are two digits long. Is it possible to (in case the length is not three) add leading zero's, just to make it length(3)? I know this is possible with a custom java code (component), however I would like to fix this with a regular expression replace. Anyone some suggestions?
"ID","TITLE"
"123","Title 1"
"456","Title 2"
"78","Title 3"
Highlighted
One Star

Re: Add leading zero's

Hi
If you want to have a value like "078", you have to change this column as String.
Regards,
Pedro
Highlighted
One Star

Re: Add leading zero's

Hi
If you want to have a value like "078", you have to change this column as String.
Regards,
Pedro

Thanks; forgot to mention, the column IS a string.
Highlighted
One Star

Re: Add leading zero's

I use :
String.format("%3s", <your field> ).replaceAll(" ", "0")
Highlighted
One Star

Re: Add leading zero's

I use :
String.format("%3s", <your field> ).replaceAll(" ", "0")

Thanks! Little improvement to your code:
String.format("%03d", Int.parseInt(row7.ID));
This will add "0"'s to your integer, with a maximum of 3 digits long.

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