HOW TO

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

First Published: October 16, 2024
Last Published: September 8, 2026

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.

Browse this article for the 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 ArcGIS Enterprise on Windows and Linux: Add or delete 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 ArcGIS Enterprise on Windows and Linux: Calculate field values 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 numbers;

// Populate the data in an integer field
return Number(numbers);
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

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options