Monday, February 22, 2010

Inserting Characters into a String - The Latest Addition to Batch Edit String Fields Toolbox

This post serves as a response to a comment posted by Josh on the Find and Replace entry. Josh commented:

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

Josh,
Thank you so much for your question and for visiting my blog. There are a couple ways of doing this:

1) You can use the field calculator in the layers attribute table using the following expression:
Left( [FieldName], 1) & "ap" & Right( [FieldName], Len( [FieldName]) -1)
So in this example, "ap" is added to the first character of the string (the Left function with the number 1 returns the first character), and then the characters of the original string minus the first character (the Right function with the number -1 returns all characters from the right of the original string minus the first character) are added to the end. So if the string in your field is "Hpy", "ap" will be added after the first character ("H"), and then the rest of the original string ("py") is added to the end. See the post on String functions for ArcMap Field Calculator for more VB examples for altering strings.

2) Thanks to your question, I added a new script to the Batch Edit String Fields toolbox I blogged about last September. Below is a graphic of this new tool.



The toolbox and scripts can be downloaded from the Geospatial Database. Use the link below to download the zip file. Ensure that the files are unzipped to the same folder (the scripts use relative paths).

Batch Edit String Fields.zip

4 comments:

  1. Just came across your blog. Great stuff! Thank you for taking the time to make this available.

    Saw you went to Mary Washington. I went to Hampden-Sydney for a few years before it was time to take life/academics seriously. Still love that area of the country.

    be well . . . Ray

    ReplyDelete
  2. Brooke,

    In searching for an Arc sollution, I have just come across your blog. Great site and thanks for your efforts to help us out. I have been using Hawths Tools Intersect Point for years to setup point data sets for some external Data Mining analysis. I setup a grid of points based on a DEM, then intersect this point data with successive grids and shapefiles to get a fully attributed data

    ReplyDelete
  3. Hi Phil,

    Thanks so much for your comment and checking out my blog! I'm glad you found it helpful!

    Brooke

    ReplyDelete
  4. This so saved me today, you have no idea. Thanks so much!

    ReplyDelete