HOW TO

Extract numbers from a field in the ArcGIS Enterprise portal and ArcGIS Online

Last Published: October 16, 2024

Summary

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.

The Geodetic field is selected in the table from the Item Page

Procedure

  1. Log in to the ArcGIS Enterprise portal or ArcGIS Online and click Content > My Content.
  2. Click the hosted feature layer to open the item details page.
  3. Add a new field. Refer to Portal for ArcGIS: Add a field or ArcGIS Online: Add a field for instructions. In this example, a new field, ‘Numbers’, is added to the attribute table.
  4. Calculate the field values to extract numbers using Arcade. Refer to Portal for ArcGIS: Calculate values for a field or ArcGIS Online: Calculate values for a field from the item page for instructions.
  5. In the Expression box, specify the following Arcade expression:
    1. Retrieve the value from the field. Replace '<fieldName>' with the actual name of the field.
var textField = $feature.<fieldName>;
  1. Store the numbers extracted from the field.
var numbers = "";
  1. Iterate through each character in a string, identify the numeric characters, and concatenate them into a separate string.
for (var i = 0; i < Count(textField); i++) {
    var char = Mid(textField, i, 1);
    if (IsNan(Number(char)) == false) {
        numbers += char;
    }
}
  1. Return the numbers.
// 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;
  1. Click OK.

The image below shows the numbers are extracted to a new field in the attribute table.

The numbers are extracted to a new field in the attribute table

Article ID: 000033749

Software:
  • ArcGIS Online
  • Portal for ArcGIS
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

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