Thursday, October 29, 2009

Find and Replace

This post is a response to a question from Ivar that was posted under the Batch Edit String Fields blog entry. The question was:

Brooke, I'm looking for a script that deletes or replaces some characters from string values. I have one field where the string values will be used as names for feature classes when I split the feature class into many, one for each feature. Example: I would like to replace the text "1630089 - 1630" with "16300891630" or "1630089_1630" (I'm not sure which one will work). It is the " - " part of the string that is the problem. I see that I might find a sollution by using several of the scripts posted by you, but if there is one script that will do the job, I'm grateful for directions.


Replacing the text in a string field can be accomplished with the Find and Replace tool available in core ArcGIS Desktop at all license levels. To do this:

1) Start editing.
2) Open the attribute table.
3) Click on the field heading containing the field text you want to replace to ensure only that field will be altered.
4) Click the Options button at the bottom of the attribute table and choose Find and Replace.
4) A dialog box opens with two tabs. Select the Replace tab. Choose to find " - " (without the quotes). If you want to replace it with an under score (like 1630089_1630), enter "_" (without the quotes) in the Replace input box. If you want to combine the text on either side of the " - " (like 16300891630) simply leave the Replace input box blank.

5) Check on the Search Only Selected Field(s) option and select to match Any Part of the text.
6) Select Replace to replace the values one at a time (might be good to do this for the first couple to make sure you are getting the desired result) or select Replace All to replace all of the values at once.
7) Save edits and stop editing.

Thanks for reading my blog and posting your question, Ivar. I hope this does what you are looking to accomplish.


  1. I probably wasn't clear about that, but I need this when building a process in Model Builder. Can I access this function in Model Builder?


  2. When I have to do some more sophisitucated changes in strings I am usually exporting table to MS Excel or Total Commander. There you can find a lot of string changing options. But in most cases modules of ArcGIS are enough.

  3. I found a solution by adding a new field and populating the field by using this expression in Field Calculator:
    Left ([Name], 8) & Right ([Name], 4)
    It's allways easy when you have found the sollution.
    Thanks anyway!

  4. Ivar,
    I'm glad you found a solution. In case you are interested, I wrote a new script called Find and Replace that will also accomplish what you are trying to do. See the latest entry ( to download the toolbox with this new script.


  5. Brooke,
    Let me ask a variant of Ivar's question. Ultimately I can resolve my situation the same way he identified above, however, is there a way to insert specified characters at a specific position. For instance; insert "ap" at position 2 from left for the field "Hpy" to create "Happy"? Any Ideas? Thanks. Nice site. Josh

  6. Hi Josh,

    Thank you so much for posting your question. See my latest entry:

    There are a couple solutions for you that I explain in the post. Feel free to email me if you have any questions or problems with either method.

    Thank you for checking out my blog!


  7. Thanks for the quick reply Brooke. I used a variation of your example in the field calculator and it worked as described. It made editing about 1500 entries much more efficient. Thank you for your time and help. Josh