1

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

xxxx-xxxx-x
xxxx-xxxx-x
xxxx-xxxx-x
xxxx-xxxx
xxxx-xxxx
xxxx-xxxx

  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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 19, 2017 at 20:33
0

1 Answer 1

4

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
 else:
 return field

Expression:

removedash(!stringfield!)

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

enter image description here

enter image description here

answered May 19, 2017 at 21:11
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.