Select to view content in your preferred language

Field Calculator

10835
14
05-18-2016 06:09 AM
LianaSmith
Frequent Contributor

I need to exclude all values that contain any letter from one of the fields. Basically only integers should be left. What code (Python/VB) do I have to put in field calculator for that?

Thanks!!!

0 Kudos
14 Replies
LianaSmith
Frequent Contributor

I removed space and got this error...

Then I tried to use single quotes like you wrote and got this:

0 Kudos
DanPatterson_Retired
MVP Emeritus

The following works as a field calculator expression in Pro and also in ArcMap.  Check the details

Field_calc01.png

LianaSmith
Frequent Contributor

Thank you !

0 Kudos
TedKowal
Honored Contributor

LOL  I just got back to the office....  I only jumped in because it sounded like she only wanted to ignore those rows that had a character in it...   When using python, now, I avoid nulls and put an empty/blank/unused code  filter and delete in a two step process since I do not trust finding nulls yet in python.

Liana  I am happy you got it worked out!  That's all the matters!

LarryStout
Deactivated User

Liana,

Using Python, the Codeblock (Pre-logic Script Code) would be:

def result(value):
    import re
    return ""  if re.search("[a-zA-Z]", value) else value

And the calculation would be:

result( !<FIELD_NAME>! )

Be careful overwriting the same field.  You can't undo it unless you start an edit session first.

Larry