Extracting an integer from a string field

86620
10
12-22-2013 04:24 PM
PhilFreeman
New Contributor II
I have an attribute table with a column populated with road names.  The names are in the form, "State Hwy 13", "US Hwy 1", "County Rd 444", etc.  I have created another column in the table which I would like to populate with just the numerical portions of these road names.  I thought this would be easy with the field calculator, but I am finding that to not be the case.  I would like to use Python, but if VBScript would work better, that would be ok as well.  Please keep in mind that I know very little about Python and have used Visual Basic only in Excel macros, so if you post some code, do not leave anything out thinking I will know what is missing.  I am running ArcMap 10.2  Any help will be greatly appreciated.
10 Replies
DanPatterson_Retired
MVP Emeritus

do you mean like int(str) or float(str)... I never liked Val("1") when you wanted a float or Val("1.0") when you wanted an integer.  The explicit casting of int(str) and float(str) are nice and for the bold.... complex("1") => (1+0j) even does casting into the complex plane

0 Kudos