I am using Python in the Field Calculator to split an address field and I cannot find the string function I need for my function. Basically, what I want to do is create a function to say if 'CIR' is in the string name return everything before 'CIR', but not 'CIR'. I am just trying to get the street name, not the street type in the field.
Here is what I have so far:
def street_name (st_name):
if ' CIR' in st_name:
I cannot find a string function to return everything to the left of 'CIR'. Thank in advance everyone.
Solved! Go to Solution.
As a start, I don't have an exact answer for you, but a suggestion to try. I was thinking you could use Replace, but put "" instead of what was used (see thread):
That said, I'm sure some of the experienced Python folks have a more elegant solution, so I'm curious to see what they come up with.
Chris Donohue, GISP
Wouldn't this return unwanted results if the street name started with CIR? For example: W CIRCLE VIEW DR
I'm doing something similar and I use str.rpartition()
head, sep, tail = st_name.rpartition(" CIR") if tail == '': return head
If the tail partition string is empty, you know there is nothing else after the separator and it's safe to return the head.