Select to view content in your preferred language

Field Calculator expression question!

2082
13
07-28-2011 08:17 AM
SeanKroencke
Emerging Contributor
I have a field that has City, State, Zip in it. I'd like a new field with the zip code only in it, and then I'd like to be able to remove the zip from the original field. Is there a way to do this?

Possibly an expression that removes all #'s?
0 Kudos
13 Replies
BruceNielsen
Frequent Contributor
Try this, after you have extracted the zip code:
!fieldname![:!fieldname!.rfind(!newzipfield!)].strip()

The .strip() is to get rid of any spaces that were between the state and zip code.
0 Kudos
SeanKroencke
Emerging Contributor
Another win, thanks so much!
0 Kudos
SeanKroencke
Emerging Contributor
I have another dataset that I'm trying to perform these calculations on.. however the formatting in this dataset is not uniform. There are sporadic spaces, punctuation, and repeats of state abbreviations, etc. Is there a python method to remove numbers, only show numbers, remove letters, etc.?

Thanks
0 Kudos
BruceNielsen
Frequent Contributor
Your best bet is to start browsing the different string methods that are available. These are your building blocks for manipulating strings. That way you can start building your own solutions to these problems as they arise.

In the on-line documentation (for version 2.7) they are found in section 5.6.1. In my local help document (ver. 2.4) it is section 2.3.6.1.
0 Kudos