Wednesday, December 1, 2010

From/To Replace String - Another Addition to the Batch Edit String Fields Toolbox

From/To String Replace is the latest script added to the Batch Edit String Fields Toolbox (see the Batch Edit String Fields - Free Tools for Calculating String Fields entry). A coworker needed to edit a field for labeling River polygons on a cartographic product in ArcMap. The field was a Name field but contained extra unwanted verbiage in parentheses to further explain the Name. For example:

New River (North Carolina portion)

and

Roanoke River (Lake Gaston below normal full power pool elevation 200 MSL)

She only wanted the labeling to show the river name, and not the explanation contained in parentheses. The Find and Replace script in the Batch Edit String Fields Toolbox is handy for replacing known substrings in a text field, but in this case, anything could be within the parentheses, so using the Find and Replace script wouldn’t work. [Enter the new From/To String Replace script!]

See the image of the script below. With this script, the starting character as well as the ending character of the substring you’d like to replace/remove is taken into account. The Replace With parameter is for the new string that will replace the characters to be removed. If there is nothing to replace the removed string with (like in the example above), the Replace With parameter can be left blank, and the substring will simply be removed from the field.

The From/To String Replace script can be downloaded as part of the Batch Edit String Fields Toolbox from the Geospatial Database. Feel free to provide feedback if you found this useful or if you have ideas for further enhancements.

Batch Edit String Fields Toolbox

*Note: These scripts were written in ArcGIS Desktop 9.3 and 9.3.1. They will work in ArcGIS Desktop 9.2. 9.3, 9.3.1, and 10.0 at the ArcView, ArcEditor, and ArcInfo license levels. Python 2.4, 2.5, or 2.6 is also required.