Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have three text fields populated as follows: 1, 9, 1 that I need to concatenate into a field that looks like 01.09.01. Getting to 1.9.1 is easy but can anyone help out with how to formulate it so that each value has two places (i.e. add in those zeroes). I used to do this in Excel but can't figure out how to work in ArcMap 10.

share|improve this question

Use the zfill() command in Python. Set your Field Calculator parser to Python, and do this:

share|improve this answer

"0"& [field1]&".0"& [field2] & ".0" & [field3]
This comment makes me start thinking of regex, (if you Must have a hard field with all these values) I am not too good with regex but I know it can fix this. not sure what the use case is.

share|improve this answer
Erm, what if there is a number larger than 9? – blah238 Nov 30 '12 at 22:14
Don't think regex is the answer here. – blah238 Dec 1 '12 at 0:11

Generally, I do something like the following in Python, to pad with leading '0's to whatever length is needed:

while len(yourString) < 5:
    yourString = '0' + yourString
share|improve this answer
That is slightly insane -- although probably not far from the internal C implementation of the pad function used by rjust, zfill, etc. – blah238 Dec 1 '12 at 0:02
Line 3142 of stringobject.c in cpython: for the pad function :) – blah238 Dec 1 '12 at 0:09

Here is a simple Python function that right-justifies to the specified width each item in a sequence of items using rjust and then joins them using join. A list comprehension is used to keep it short and simple. The optional arguments default to your specifications.

def padjoin(sequence, width=2, sep='.', fillchar='0'):
    return sep.join([str(item).rjust(width, fillchar) for item in sequence])

Example usage:

>>> padjoin([1, 9, 1])
>>> padjoin([1, 23, 45])

Field calculator expression (be sure to switch to the Python parser):

padjoin([str(!field1!), str(!field2!), str(!field3!)])

The str() conversion function is needed for each field reference in case there are any null values as the default field calculator behavior when a null is encountered is to stop execution and skip to the next row.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.