English

How To: Truncate a field

Summary

The Field Calculator in ArcMap allows truncating an existing value. Several Visual Basic string manipulation functions are available for truncating values.

The example provided in this article uses the Visual Basic Left function to return a specified number of characters from the left side of a string, and truncates after that number.

Procedure

 

  1. In ArcMap, right-click the layer in the Table Of Contents.
  2. Select Open to open the attribute table.
  3. In the attribute table, select Add Field from the Options drop-down list.
  4. Create a new text field.
  5. Start an editing session.
  6. Right-click the new field name in the attribute table window, and click Field Calculator.
  7. Ensure the correct parser (VB Script) and data type are selected. By selecting the appropriate data type, access to functions that can be used to edit data become available.

    [O-Image] Field Calculator VB Script and type
  8. Determine from which direction the field must be truncated.

    For example, if data in the field must be truncated from the left, and the last three numbers must be removed from each cell, use the following code in the expression box:
     
    Code:
    Left( [field_name],#) 

    where [field_name] is the field to truncate and # is the number of characters that need to be preserved.

    To truncate data from the right, use the following code in the expression box:
     
    Code:
    Right( [field_name],#) 

    where [field_name] is the field to truncate and # is the number of characters that need to be preserved.

    View the following example, which shows the original column of data (test), and result of each code (test_left and test_right).

    [O-Image] Truncate data with Field Calculator VB script
  9. Save any edits, and end the editing session.

Related Information