Select to view content in your preferred language

Stripping Text in Field Calculator using wildcard

956
7
01-24-2013 05:15 AM
NoahHuntington
Deactivated User
Is there anyway to strip text using wild card...

As in:

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

Would like to remove anything after "OUT "

HITCH ENTERPRISES, INC. WARRANTY DEED BOOK 552, PAGE 532 (NW/4) (NE/4) (SE/4)

Would like to use "Out " as wildcard for strip function instead of string position as table attributes vary?

Thanks in advance...
Tags (2)
0 Kudos
7 Replies
MathewCoyle
Honored Contributor
Something like this.
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]
0 Kudos
NoahHuntington
Deactivated User
Sort of. 

I need something that will work for a variety of instances in a field which all contain "OUT OF " a varying positions in the text...

CLAWSON LAND PARTNERSHIP WARRANTY DEED BOOK 1069, PAGE 271 & BOOK 1061, PAGE 359 (E/2 OF NE/4) (SE/4)  OUT OF SECTION 15 TOWNSHIP 1N  RANGE 16E TEXAS COUNTY, OKLAHOMA

or

HITCH ENTERPRISES, INC. WARRANTY DEED BOOK 552, PAGE 532 (W/2 OF NW/4)  OUT OF SECTION 15 TOWNSHIP 1N  RANGE 16E TEXAS COUNTY, OKLAHOMA

Thanks for the response.
0 Kudos
AndrewChapkowski
Esri Regular Contributor
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]
0 Kudos
MathewCoyle
Honored Contributor
I'm confused. How does my example not work? You simply substitute var for whatever variable holds your field value.
0 Kudos
NoahHuntington
Deactivated User
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]


This is good.  How would I rework this to work with all items in field?

Maybe something similar to:
def func():
text = !Label!
text.find("OUT OF")

print text[:loc]
0 Kudos
AndrewChapkowski
Esri Regular Contributor
I don't know what you mean by items in a field.
If you have a cursor you can do something like:
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 didn't test the code, but that's how you can break a string up by a start and stop position. 
For help with working with python standard types, please see: http://docs.python.org/2/library/stdtypes.html

Thank you
0 Kudos
NoahHuntington
Deactivated User
I'm confused. How does my example not work? You simply substitute var for whatever variable holds your field value.


You'll have to forgive me Matthew.  I am a little slow with all of this.  Would you be able to provide a screen cap of this used in field calculator?  I appreciate your input.
0 Kudos