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
- I want to query for all records that have two dashes in a string (three records in the sample above).
- 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.
1 Answer 1
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.
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.
Explore related questions
See similar questions with these tags.