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

How do I append my field values in my .dbf to correspond with the values of my feature's attribute table.

I need to append 0's to the field value if the field value is less than 11 characters in length.

It needs to be done in the field calculator through VB Script or Python.

share|improve this question
Can you give more details please? are the 0s to be added in front or behind the numbers? Why are you referring to dbf files if you want to work in field calculator? Do you want the new values to be strings or integers? – sgrieve Dec 3 '12 at 10:07

You have several options in python: zfill, interpolation operator ('%'), and rjust (pad with any character...not just zeros). See this SO question:

There's also an example here:

share|improve this answer

Using python's string multiplication, this can be done very simply in a couple of lines. The only tricky bit is that you must convert an int to a string in order to use the len() function.

Assuming the field you are working with is called x:

def pad(x):
 if len(str(x)) < 11:
  return str(x) + ('0'*(11-len(str(x))))

Which can be called with:

share|improve this answer

possibley this could be a one-liner..but i am not able to figure out for now :)

Pre-Logic Script Code:

def AppendZeroes(strContent):
    a = len(strContent)
    strTemp = ""
    if(a < 11):
        for i in range(11- a):
            strTemp =  strTemp + "0"
        strContent = strContent + strTemp
    return strContent

call it using

AppendZeroes( !YOUR_FIELD_NAME! )
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.