Pages

Sunday, May 18, 2014

Replace a certain character in a text in ArcGIS field calculator

Sometimes we need to replace some characters from the text strings in ArcGIS attribute table. The following tutorial can help.


Step 1: Right click the shapefile you want to edit and click Open Attribute Tables


Step 2: Select the Field you want to modify. Here I am selecting the "Structural" field and go to the field calculator option.


Step 3: Write the following code. For my case I want to change "M" character by "L" in Structural field which is in the 3rd position from the left (C3M).
                                                               


Replace(Left ([Structural],3), "M", "L")

This means Replace the value "M" by "L". "M" character is located from Left side in 3rd position in  [Structural] field .

If I want to change C with B then the formula would be:
Replace(Left ([Structural],1), "C", "B")

** you can use Right() string also.


After applying the formula:



In the similar way you can also delete a character from a text like

you have the ID like

ab_001
ab_002
ab_003
ab_004

You want
ab001
ab002
ab003
ab004

So you this code: Replace(Left ([ID],3), "_", "")

You can watch the video for better understanding