I want to write a Python script in Field Calculator which can pick up or choose the fist letters of words and put them in a new field.
For example:
Lepidium catapycnon..........> Lc
Gold blossom tree............> Gbt
3 Answers 3
Expanding on the answer from cag I just tested the code below which should do what you want. You just need to have your original and new field (called OrigField and NewField in my test) already in the attribute table.
Parser
Python
Pre-Logic Script Code
def Abbreviate(origFieldValue):
newFieldValue = "".join(item[0] for item in origFieldValue.split())
return newFieldValue
NewField =
Abbreviate(!OrigField!)
You can do it by splitting the words by groups of consecutive whitespaces and taking the first letter of each word.
There is a python example at Upper case first letter of each word in a phrase.
If you can write in SQL it would be something like SELECT SUBSTR(Column, 1, 2) where Column would be the name of the corresponding attribute column.
Explore related questions
See similar questions with these tags.