Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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".

share|improve this question
1  
Why the down votes? –  Nathan W Dec 26 '12 at 2:28
add comment

2 Answers

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

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

!FieldName!.replace("-","")
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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