1

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
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 12, 2012 at 17:47

3 Answers 3

7

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!)
answered May 13, 2012 at 2:00
0
2

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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered May 12, 2012 at 18:12
0
0

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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
answered May 12, 2012 at 18:03
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.