Removing numeric characters from alphanumeric value in field calculation?
I would use regular expressions. If you put the following in the code block section of the calculator it will return a string that has all digits stripped, no matter were they are:
import re
def strip_digits(s):
return re.sub("\d+", "", s)
This can then be called from the calculate box as:
strip_digits(!column_name!)
If you want to replace characters, add another argument to the function for the replacement characters, and put it in place of the empty string.
just use strip
s="AAAA-000"
print s.strip("0, 1,2,3,etc")
AAAA-
I also found this in the mapping center (arcgis.com).
resources center text management tool
It is old code written for 9.2/9.3. Not sure about appropriateness for 10.x The description reads...
- Batch Find and Replace: This tool populates strings in a text field with replacement strings that are specified in a Find/Replace table. This is useful for standardizing label strings or introducing and enforcing standard abbreviations.
- Convert Text to Proper Case: This tool converts the text strings in one field (presumed to be all upper or all lower case) to a proper case (mixed upper and lower case) text string in another (new) field. This tool is written to handle common abbreviations such as NE for northeast, so that it won't come out as Ne.
- Extract Hwy Numbers for Hwy Shield Labels: Adds the numeric portion of a highway name to another text field.
All these tools are written in Python and can be modified to accomplish any specific needs you have.