def AddZero(field): new = field[:4] + "0" + field[4:] return new;
AddZero( !your_fieldname! )
def AddPunc(field): new=field[0:2] new+="-"+field[2:4] new+="-"+field[4:6] new+="-"+field[6:9] new+="-"+field[9:12] new+="."+field[12:15] new+="-"+field[15:18] return new
from itertools import * def formatPID(in_pid, delimiter='-', groups=()): # groups are how you want to break it up in_pid = str(in_pid) it = iter(in_pid) return delimiter.join(''.join(islice(it, i)) for i in groups)
formatPID(!Your_PID_Field!, '-', (2,2,2,3,3,3))
def AddPunc(field): new=field[0:2] new+="-"+field[2:4] new+="-"+field[4:6] new+="-"+field[6:9] new+="-"+field[9:12] new+="-"+field[12:15] return new
You can add an if/then condition very easily with a length test. What kind of conditions were you thinking of adding?Here is an example of changing where to add the 0: def AddZero(field): # add after 4th char if len == 7 if len(field) == 7: new = field[:4] + "0" + field[4:] # here is the "then" statement elif len(field) == 9: new = field[:5] + "0" + field[5:] # inserts 0 @ 'xxxxx0xxxx' (after fifth position) return new;
def AddZero(field): # add after 4th char if len == 7 if len(field) == 7: new = field[:4] + "0" + field[4:] # here is the "then" statement elif len(field) == 9: new = field[:5] + "0" + field[5:] # inserts 0 @ 'xxxxx0xxxx' (after fifth position) return new;
Try this in the field calculator, be sure to set the parser to Python:Pre-logic code block def AddZero(field): new = field[:4] + "0" + field[4:] return new; And use this as the expression: AddZero( !your_fieldname! ) [ATTACH=CONFIG]24010[/ATTACH]
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.