Using ArcMap 10.2.2 and have a string field in an attribute table that has values such as:


  1. I want to query for all records that have two dashes in a string (three records in the sample above).
  2. I want to remove the second dash from the string.

I would prefer to do this in two separate steps where I can first query/identify identify the records w/two dashes and then run an update to remove the second dash.

| improve this question | | | | |
  • I want to remove just the second dash. – Steve May 19 '17 at 20:37
  • Is there always only one character after the second dash? – Midavalo May 19 '17 at 20:39
  • Yes, always one character after the dash. Thanks for editing the question to show the records vertically. – Steve May 19 '17 at 20:40

First use Select by Attributes:

"stringfield" LIKE '%-_'

This will select any record where the value in your field has a dash as the second-to-last character.

enter image description here

enter image description here

Then use the Field Calculator to remove the second dash -> Python Parser, Show Codeblock.

In Pre-logic script code:

def removedash(field):
    if field[-2] == '-':
        x = "{0}{1}".format(field[:-2], field[-1:])
        return x
        return field



Where stringfield is the name of the field you're wanting to update.

enter image description here

enter image description here

| improve this answer | | | | |
  • Thank you for the detailed response. It worked beautifully :) – Steve May 23 '17 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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