4

I want to use the Python field calculator to remove the hyphen from a field column. For example, I would like to parse out the hyphen from an entry like "123-45-6789" and read "123456789".

1
  • 1
    Why the down votes?
    – Nathan W
    Dec 26, 2012 at 2:28

2 Answers 2

12

Use the built-in str.replace method accessible on all string objects.

Make sure Python is checked in the Parser at the top

Put this in the Expression box (replacing "FieldName" with your own):

!FieldName!.replace("-","")
2

The sub method in Python's regular expression module should do the trick.

import re
no_hyphens = re.sub('-','','123-45-6789')

This will replace any instance of a "-" with an empty string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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