I have a Forest roads here with me and there is a column (iD ) that shows street name number, freeway, state, county along with their numbers..
I copied them to a new field column Symbol that I need to calculate them with just numbers only.
This purpose is to show them the road symbol number as a labels
How do I do that in the Field Calculator ?
as I suggested before
python of course
>>> a ="83N"
>>> b = "".join([i for i in a if i in '0123456789'])
>>> b
'83'
where 'a' is !yourfield!
where a is your field and b will be your new field which you don't have to specify. This could be used directly in the field calculator
AND
it will not work in all cases as I stated before since I doubt that highway 360.2B is going to come out as 360.2 but 3602.
multiple steps may be necessary.
If you want a numeric value, wrap the whole thing in an int( ) statement
Where exactly is the number in "MOR-Q"? Does this have what you call a number, or is there no number for this one?
Can account for it... but it is getting less elegant
>>> a = "MOR-Q" >>> b = "".join([i for i in a if i in '0123456789']) >>> b ''
or for the devil's highway in nodata form
>>> b = ["".join([i for i in a if i in '0123456789']) or -666][0] >>> b -666
Wait, Dan, what happened to the smoking one-liner (of code)?
(just kidding)
Chris Donohue, GISP
There are probably some in the long history of this question... How do you write expression in Label field to replace string with values ? Nothing seems to work, I think the questions are asked and forgotten.
Sorry -- I just could not resist ..... Temptation got the better of me!
int(filter(str.isdigit, [ID]))
BTW: I had an access denied when trying to use the advanced editor....
trying to cut down on filter, map and lambda... beginning to forget their usefulness
VBScript or Python ?
Tried and gave me the error
If you want to try vbscript:
int([ID])
Of course those string with no numbers will come out to be 0.