You could include the Python dictionary of state abbreviation:full-name pairs here
states = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
# etc...
}
as the Codeblock in Field Calculator, and then use something like the following as the actual calculation:
!City! + ", " + states[!State!]
I should add that you could perform this calculation on either a new (text) field, or on the existing City field (or any other already-existing text field). I would recommend creating a new one, as you will otherwise not be able to easily revert to a field of only city names if you ever need them.
Well, I agree with one of the comments above about using Maplex if that will work for you. If it doesn't though, what you could do is use the field calculator as you suggest. For the all initials (J H S & L L S) You would want to do something like the following:
Code Block / Pre-Logic Script Code:
def nameCalc(inName):
outName = ""
namesList = inName.split("&")
for name in namesList:
outName = outName + " &"
nameL = name.split()
for word in nameL:
outName = outName + " " + word[0]
outName = outName.strip(" &")
return outName
and then in the expression you would put nameCalc(!Owner_Nm!)
You could select the parcels you want just initials for and then run that. However, if you want to do them all at once and you have an area field or such as that that you want to use to automate the process (ex: all parcels larger than or equal to 5 acres get full name, between 5 and 1 acres get abreviated, and smaller than 1 gets just initials), then you could do something like the following in the code block:
def nameCalc(inName,area):
outName = ""
if area < 1:
namesList = inName.split("&")
for name in namesList:
outName = outName + " &"
nameL = name.split()
for word in nameL:
outName = outName + " " + word[0]
outName = outName.strip(" &")
if area >= 1 and area < 5:
namesList = inName.split("&")
for name in namesList:
outName = outName + " &"
nameL = name.split()
for word in nameL:
if word != nameL[-1]:
outName = outName + " " + word[0]
else:
outName = outName + " " + word
if area >= 5:
outName = inName
outName = outName.strip(" &")
return outName
and then in the expression you would put nameCalc(!Owner_Nm!,!Acres!)
PLEASE NOTE THOUGH: if you do that, you would A) Have to replace the 1, 1, 5, & 5 with the appropriate values for your data and what you want and B) you would have to replace !Acres!
in the expression with whatever area/size field you wanted to use and that field would have to be a numeric field for the code above to run correctly.
I know that's a lot of code, and it may be a bit to work your way through, but it should return each of the 3 desired results and will correctly handle both single names and double names separated by &
I hope that helps, and if you have questions, feel free to comment and if I can help, I will try to.
Best Answer
Check out the replace function in the calculate field examples. Something like this should do it: