Field Calculate Need Last Word of String

6146
16
08-17-2016 10:16 AM
CindyLewis
Deactivated User

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 Emeritus

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
Deactivated User

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
Deactivated User

i

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

use to Python... THANKS

0 Kudos
DanPatterson_Retired
MVP Emeritus

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
Deactivated User

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 Emeritus
 >>> a = "Do you mean this Mountain View Farms Blvd"
>>> " ".join(a.split(" ")[:-1])
'Do you mean this Mountain View Farms'

0 Kudos
CindyLewis
Deactivated User

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

thanks

0 Kudos
JoeBorgione
MVP Emeritus

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
Deactivated User

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