Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to write a script (Python or VB) 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

I'm thankful if someone can help me with it.

share|improve this question
add comment

3 Answers 3

up vote 7 down vote accepted

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!)
share|improve this answer
    
Worked pretty well. Thanks heaps. –  Matt May 14 '12 at 14:50
add comment

You can do it by splitting the words by groups of consecutive whitespaces and taking the first letter of each word. You've got a python example here.

share|improve this answer
    
Thanks.............................. –  Matt May 14 '12 at 14:57
add comment

Does it have to be in python or vbscript? 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.

share|improve this answer
    
Thanks...................................... –  Matt May 14 '12 at 14:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.