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 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. In this example, the CompanyNew field is created.
Note:
Ensure to select the String data type when creating the new field.
- Click Menu on the header of the new field and select Calculate. In this example, CompanyNew is selected.
- For Field, click the drop-down menu to select the field. In this example, CompanyNew is selected.
- For Select language, select Arcade.
- Click Next.
- Specify the Arcade 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 Run to verify the expression, and click Run calculation to apply the query.
The table below demonstrates the CompanyNew field populated by values from the Company field with the trailing characters removed.