English

How To: Remove numbers from a string field

Summary

The instructions provided describe how to remove numbers from a string field in an attribute table using the Field Calculator in ArcMap. In this example, Python code is used to remove the numbers in a string field without having to edit every record individually.

Procedure

To remove numbers from a string field in an attribute table:

  1. In ArcMap, click the Editor drop-down menu on the Editor toolbar, and select Start Editing.
  2. In the Table Of Contents, right-click the selected layer, and select Open Attribute Table.
An image of a string field consisting of numbers in an attribute table.
  1. Right-click the field, and select Field Calculator.
An image on how to open a Field Calculator in the attribute table.
  1. In the Field Calculator, select the Python parser, and check the Show Codeblock check box.
  2. In the Pre-Logic Script Code box, copy and paste the following code:
import re
def strip_digits(s):
    return re.sub("\d+", "", s)
  1. Copy and paste the following code in the second box:
strip_digits(!Field_Name!)
  1. Replace !Field_Name! by double-clicking the field in the Fields list.
 An image of the Field Calculator.
  1. Click OK, and the numbers are removed from the string field, as shown in the image below.
An image of the Street field after removing the numbers.
  1. In the Editor toolbar, select Stop Editing and Save Edits to keep the changes.

Related Information