def losemunitype( name): lsttypes = ['County', 'Parish', 'Borough', 'Municipality', 'Census Area', 'City and Borough'] for losetype in lsttypes: if losetype in name: return name.replace(losetype, '') return name
def losemunitype( name): lsttypes = ['County', 'Parish', 'Borough', 'Municipality', 'Census Area', 'City and Borough'] for losetype in lsttypes: if name.endswith(losetype): return name[:-len(losetype)].strip() return name
Ok. This works on your sample data.In Field Calculator...1. Change parser to python2. Check Show codeblock3. Paste the code below into Pre-logic script code4. in the name = box, enter losemunitype(!name!) def losemunitype( name): lsttypes = ['County', 'Parish', 'Borough', 'Municipality', 'Census Area', 'City and Borough'] for losetype in lsttypes: if losetype in name: return name.replace(losetype, '') return name
There are a lot of different ways to do this, but I would use this:[Name].rstrip("Census Area").rstrip("Municipality").rstrip("Borough").rstrip("City and Borough").rstrip("Parish").rstrip("County").rstrip()The last .rstrip() gets rid of any spaces at the end of the new string.
[Name].rstrip("Census Area").rstrip("Municipality").rstrip("Borough").rstrip("City and Borough").rstrip("Parish").rstrip("County").rstrip()
In vbscript: Left([Name], Len([Name])-6)Basically this prints anything on the Name field and ignoring the last 6 character, which is dropping off the " county"(note the space character).Hope it helps!Cheers,Raymond
Thanks raymondhuang - I unfortunately get an error message saying "No features found. Could not verify expression."Any ideas? Thanks again.
[Name].split()[:-1]
[Name].rstrip(" Country")
In python:!Name!.split()[:-1]
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.