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.
closed as off-topic by Midavalo♦ Jun 14 '17 at 23:58
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – Midavalo
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: