Select to view content in your preferred language

How to label "_, Mount" as "Mount _" ?

1808
11
Jump to solution
05-08-2018 01:46 PM
CoryBoschman
New Contributor II

I am trying to make labels for all the named peaks across British Columbia. The name string in the attribute table has many entries like "Rad, Mount" or "Rad Peak, The", and I'd like to display them on the map as "Mount Rad" or "The Rad Peak". There are about 13,000 features in the table with only maybe a quarter that need to be changed.

Any suggestions on the best way to accomplish this?

0 Kudos
11 Replies
CoryBoschman
New Contributor II

GOT IT! Thanks Dan!

After getting it to work in the field calculator I put this in to the label field expression and it seems to be working

0 Kudos
DanPatterson_Retired
MVP Emeritus

Ahhh a brain nimbler...

replace fld with your source field name in ! marks  ie !YourField!

Python parser, in the field calculator for a new text field obviously

# ---- a sample 'field'

fld = ["Last, First", "Ok", "two last, first", "right order", "Rad Peak, The"]

# ---- the field calculator expression, python parser

[[i, " ".join(i.split(", ")[::-1])][", " in i] for i in fld ]

# ---- result

['First Last', 'Ok', 'first two last', 'right order', 'The Rad Peak']

might not work in all circumstances, so try it on a few and worry about the corner cases later