Add leading zero's

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.