1

In a feature class field (screenshot below), I'd like to know how I can get a count of the alpha characters in each record and calculate it to a new field. I have a "FieldCount" field that calculates the total number of characters in the ENGPLANDWG field. I'd like to do the same thing but just for alpha characters where "F63Y" would calculate to 2 (F & Y). I'm using ArcGIS 10.2.2.

Screenshot

2
  • 2
    This is a question that I think you would quickly find an answer to at Stack Overflow because the part where you are stuck is pure Python.
    – PolyGeo
    Jun 13, 2017 at 20:19
  • If you try looking at Stack Overflow then make a code attempt here your question will be better placed for re-opening.
    – PolyGeo
    Jun 13, 2017 at 20:44

1 Answer 1

2

This is straight python, so would have been better to ask this on Stack Overflow, however this should work for you.

In your field calculator, select Python Parser and Show Code-block.

In Pre-logic script code:

import string
def count_alphas(mystring):
    i = 0
    for char in mystring:
        if char in string.ascii_letters:
            i += 1
    return i

And in the expression:

count_alphas(!ENGPLANDWG!)
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.