Geographic Information Systems Asked on May 30, 2021
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
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!)
Correct answer by PolyGeo on May 30, 2021
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.
Answered by FishHead on May 30, 2021
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.
Answered by César Argul García on May 30, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP