I'm looking for a Python or VB statement to remove the last part of a string, starting where the 1st non Numeric character appears, using the Field Calculator in ArcMap 10. Here's an example of what I'm looking for:
Is it possible?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Here's a go at it. Use Python as the parser and check show Codeblock.
Enter this in the top Pre-Logic Script Code box:
def getints(field): integers =  for char in field: try: value = int(char) integers.append(str(value)) except ValueError: break return "".join(integers)
And put this in the bottom box:
Here is a field calculator method that incorporates itertools.takewhile. While ian's solution writes the new values to a text field, this is suited for writing to a numeric field.
import itertools def convert(x): try: return int("".join(itertools.takewhile(str.isdigit, str(x)))) except: pass