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.
Procedure
- 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.
- 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.
- Click the field header and select Calculate. In this example, CompanyNew is selected.
- In the Calculate Field dialog box, click Arcade.
- In the Arcade Calculator dialog box, specify the Expression field as follows:
Replace($feature.<field_name>, "<text_value>", "")
- Replace <field_name> with the name of the field from which the characters are to be removed. In this example, Company is used.
- 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>"," ")
- Click Test to verify the expression, and click OK to apply the query.
The attribute table below demonstrates the CompanyNew field populated by values from the Company field with the trailing characters removed.