I got table field from the county and I just want to extract city from the addresses provided, I don't have any python background.
sample table field situs_addr:
123 street name, city state zip
45 street and street, city state zip
1000 street blvd, city name state zip
I successfully got the address number with street name separated using "split"
!situs_addr!.split(',')[0]
but I'm having a hard time figuring out how to extract just the city, since the length of each addresses are different.
Thank you!
Solved! Go to Solution.
pre-logic window (python):
def func(string):
#could make this better but does the job probably
if len(string) > 0:
result = (" ".join(((a.split(',')[1]).split(" "))[:-2]))[1:]
else:
result = ""
return result
code window below pre-logic window:
func(!situs_addr!)
The OP didn't state (no pun intended) whether State is name or postal abbreviation. It is likely the latter, but if the former, this approach will fail on several states.
Of course! I even assured myself that all states had one word names.
(" ".join(( !Situs_Addr! .split(',')[1]).split(" "))[:-9])
I just selected the one with addresses and this code works!
Thank you so much!