HOW TO
In the ArcGIS Enterprise portal and ArcGIS Online, it is possible to extract numbers from a field using an Arcade expression. This is useful for data management, better readability, and analyzing numerical data. For example, the zip codes from a list of addresses can be extracted to sort the locations.
This article provides the workflow to extract numbers from a field using Arcade in the Calculate Field tool to populate them in another field. In this example, the numbers are extracted from a field named Geodetic.
var textField = $feature.<fieldName>;
var numbers = "";
for (var i = 0; i < Count(textField); i++) { var char = Mid(textField, i, 1); if (IsNan(Number(char)) == false) { numbers += char; } }
// Populate the data in a text field return number; // Populate the data in an integer field return Number(number);
Note: When populating an integer field, if there are no numbers found, the number zero (0) is populated in place.
The code block below shows an example of the full working script to populate a text field.
var textField = $feature.Geodetic; var numbers = ""; for (var i = 0; i < Count(textField); i++) { var char = Mid(textField, i, 1); if (IsNan(Number(char)) == false) { numbers += char; } } return numbers;
The image below shows the numbers are extracted to a new field in the attribute table.
Get help from ArcGIS experts
Download the Esri Support App