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

Re: Add leading zero's

I use :
String.format("%3s", <your field> ).replaceAll(" ", "0")
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.

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

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