About EasyMorph Tutorials & Examples Web-help

Adding leading zeros to numbers


#1

Hi there,

I have a column with numbers from 129 to 8712.
I would like to add leading zeros, 129 --> 0129, so that all numbers have 4 digits.

I can do it with RegEx in a Textfile, Search:^(\d{3})\t —> ‘\t’ because I use tabstops to separte colums in the textfile
Replace: 0\1

But in the RegEx-Transformation in EasyMorph I can only search but not replace with RegEx. I’m not that good with the functions in EM, maybe there is a way to perform this task?

Greets,
Nima


#2

Hi Nima,

You can do it with Modify column transformation and the following expression:

padstart([Column name], '0', 4)

Here is an example project: PadNumbers.morph (1.2 KB)

Thanks,

Andrew


#3

Hi Andrew,

thank you very much ! Works perfectly! I knew there must be an function that I don’t know about.

Thanks,

Nima


#4

You are welcome!