HOW TO

Remove specific characters from a string field using Arcade in ArcGIS Online

Last Published: September 12, 2023

Summary

Removing specific characters from a string field can be useful for data management, and in ArcGIS Online, it is possible to remove them using an Arcade expression. The replace() Text function in ArcGIS Arcade is used to remove these leading or trailing characters.

The Company field containing trailing characters, as shown in the attribute table below, is used to demonstrate the workflow in this article.

String field with specific trailing text characters

Procedure

  1. In ArcGIS Online, click the desired hosted feature layer. On the item details page, click the Data tab.
Note: 
Skip to Step 3 if the script is run on an existing field.
  1. In the Table view, create a new field. Refer to ArcGIS Online: Add a field for instructions. Ensure String is selected from the Type drop-down list. In this example, the CompanyNew field is created.
  1. Click the field header and select Calculate. In this example, CompanyNew is selected.
  2. In the Calculate Field dialog box, click Arcade.
  3. In the Arcade Calculator dialog box, specify the Expression field as follows:
Replace($feature.<field_name>, "<text_value>", "")
  1. Replace <field_name> with the name of the field from which the characters are to be removed. In this example, Company is used.
  2. Replace <text_value> with the value of the specific characters to be removed. Here, ‘-#’ is used, and in the Arcade expression, " " is added as the value to replace ‘-#’  as it represents an empty text value. If there are multiple, separate characters to be removed, run the replace() function multiple times, as in the following expression:
Replace(Replace($feature.<field_name>, "<text_value1>"," "),"<text_value2>"," ")
  1. Click Test to verify the expression, and click OK to apply the query.
Expression to remove specific trailing characters in Arcade Calculator dialog box

The attribute table below demonstrates the CompanyNew field populated by values from the Company field with the trailing characters removed.

String field without specific trailing characters

Article ID: 000030333

Software:
  • ArcGIS Online

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options