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.
Use the zfill() command in Python. Set your Field Calculator parser to Python, and do this:
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])
>>> padjoin([1, 9, 1]) '01.09.01' >>> padjoin([1, 23, 45]) '01.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.