Select to view content in your preferred language

Truncate Address in String Field

903
2
10-24-2012 06:30 AM
StevenSmith1
Emerging Contributor
I would like to remove city codes from the end of addresses that need to be geocoded and was wondering if there's a simple field calc formula to do this?

For example looking to take 123 Main St-AABB and calculate 123 Main St into a new field removing the city code AABB.

I have over a thousand addresses so going through deleting by hand is not an option.

Thanks
Tags (2)
0 Kudos
2 Replies
by Anonymous User
Not applicable
If every record has the city code after the address separated by a dash, this can be done very easily with the field calculator.  Set the parser to Python and put in this expression:

!field_name!.split("-")[0]


This will return everything before the dash, in your case "123 Main St"
0 Kudos
StevenSmith1
Emerging Contributor
Thank you!

I was trying that but without the [0] at the end and it wasn't working.

I did end of getting the same result from using a combination of the InStr() to find location of "-" then Left ([fieldname], [InStr] -1) but this is one less step and faster.

Thank you again for all your help!
0 Kudos