var = 'HITCH ENTERPRISES, INC. WARRANTY DEED BOOK 552, PAGE 532 (NW/4) (NE/4) (SE/4) OUT OF SECTION 29 TOWNSHIP 1N RANGE 16E TEXAS COUNTY, OKLAHOMA'
keepVar = var.split('OUT')[0]
text = "HITCH ENTERPRISES, INC. WARRANTY DEED BOOK 552, PAGE 532 (NW/4) (NE/4) (SE/4) OUT OF SECTION 29 TOWNSHIP 1N RANGE 16E TEXAS COUNTY, OKLAHOMA"
loc = text.find("OUT OF") #"OUT" works the same
print text[:loc]
You can try this as well:text = "HITCH ENTERPRISES, INC. WARRANTY DEED BOOK 552, PAGE 532 (NW/4) (NE/4) (SE/4) OUT OF SECTION 29 TOWNSHIP 1N RANGE 16E TEXAS COUNTY, OKLAHOMA" loc = text.find("OUT OF") #"OUT" works the same print text[:loc]
def func():
text = !Label!
text.find("OUT OF")
print text[:loc]
with da.SearchCursor(<data>, [fields]) as cursor:
for row in cursor:
fieldValue = row[cursor.fields.index("fieldname")]
startWord = row[cursor.fields.index("startWordField")]
stopWord = row[cursor.fields.index("stopWordField")]
stop = fieldValue.find(stopWord)
start = fieldValue.find(startWord)
print fieldValue[start:stop]
I'm confused. How does my example not work? You simply substitute var for whatever variable holds your field value.