Monday, 12 November 2018

python - How to delete last part of a string starting from the 1st non numeric character?



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:


enter image description here


Is it possible?



Answer



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:


getints(!YOURFIELD!)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...