Field Calculate Need Last Word of String

3584
16
08-17-2016 10:16 AM
CindyLewis
New Contributor II

I am working with street names and need only the suffix returned (Dr, Blvd, St, Pkwy)

ei. Mountain View Blvd      = Blvd

I attempted to go from the right to left and looking for the first space " " from the right (between View _ Blvd) to split?

in VBA if possible

Thanks

0 Kudos
16 Replies
DanPatterson_Retired
MVP Esteemed Contributor

if it is space delimited, and strip... first and last as examples... time to use python... so set your parser accordingly

>>> a = "Mountain View Blvd"
>>> a.split(" ")[0].strip()
'Mountain'

>>> a.split(" ")[-1].strip()
'Blvd'

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
CindyLewis
New Contributor II

Thank You so very much! Now, how do I delete the suffix off the original Mountain View Blvd to generate Mountain View?

0 Kudos
CindyLewis
New Contributor II

i

I found something along this line that works well,, although I am not very

use to Python... THANKS

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

Yes, that is good, but it can be simplified into

>>> " ".join(a.split(" ")[:-1])
'Mountain View'

by just replacing 'a' with !Your_Field_Name!   or whatever your fieldname is, just make sure you surround it with exclamation marks

CindyLewis
New Contributor II

Thanks that sounds easier (does that work with however many words may be in the field?

ei Mountain View Farms Blvd?)

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor
 >>> a = "Do you mean this Mountain View Farms Blvd"
>>> " ".join(a.split(" ")[:-1])
'Do you mean this Mountain View Farms'

0 Kudos
CindyLewis
New Contributor II

yes, I have 1000+ various street name to break up that are all different

thanks

0 Kudos
JoeBorgione
MVP Esteemed Contributor

Not to steal any of dan's thunder, but here is a link to a thread that really helped me out: 

https://community.esri.com/thread/163731 

The calc script provided there in works wonders for me!

That should just about do it....
0 Kudos
CindyLewis
New Contributor II

I will definitely be using that in the future! Thanks Joe.

actually for now I just have the street name to split out, maybe I was going about this a bit backwards! LOL

newbie here.

0 Kudos