HOW TO

Rearrange text strings of labels using Arcade in ArcGIS Pro

Last Published: August 28, 2023

Summary

In ArcGIS Pro, Arcade expressions with multiple statements can be used to split and reposition text strings of labels. The repositioned text strings can be used for data management and this article provides the workflow using Arcade expressions.

An ArcGIS Pro map with labels is shown below.

The map with labels in ArcGIS Pro

Procedure

  1. Start ArcGIS Pro and open the project.
  2. In the Contents pane, right-click the feature class and click Labeling Properties to open the Label Class pane.
Opening the Label Class pane of the feature class from the Contents pane
  1. In the Label Class pane, click the Label expression The Label expression icon button.
  2. Select Arcade from the Language drop-down menu.
  3. Specify the following script in the Expression section.
    1. Define the variable with the function to split the text string and the blank space as a separator.
var <variableName1> = Split($feature.<featureName>, ' ')
  1. Define the variable with the function to count the number of splits for each record.
var <variableName2> = Count(<variableName1>)
  1. Specify the following statement to return a blank value when the field value is empty.
if (<variableName2> == 0) {
return ''
}
  1. Specify the following statement to return the same text value when the field is a single word.
if (<variableName2> == 1) {
return $feature.<featureName>
}
  1. Specify the following statement to rearrange the position of the second word to the first position when the field has two words.
if (<variableName2> == 2) {
return <variableName1>[1] + ' ' + <variableName1>[0]
}
  1. Specify the following statement to rearrange the position of the first word to the third position when the field has three words.
if (<variableName2> == 3) {
return <variableName1>[1] + ' ' + <variableName1>[2] + ' ' + <variableName1>[0]
}
  1. Specify the following statement to rearrange the position of the first word to the fourth position when the field has four words.
if (<variableName2> == 4) {
return <variableName1>[1] + ' ' + <variableName1>[2] + ' ' + arrName[3] + ' ' + arrName[0]
}
The code block below shows the full working expression.
var arrName = Split($feature.Forest_Name, ' ')
var lenName = Count(arrName)
if (lenName == 0) {
return ''
}
if (lenName == 1) {
return $feature.Forest_Name
}
if (lenName == 2) {
return arrName[1] + ' ' + arrName[0]
}
if (lenName == 3) {
return arrName[1] + ' ' + arrName[2] + ' ' + arrName[0]
}
if (lenName == 4) {
  return arrName[1] + ' ' + arrName[2] + ' ' + arrName[3] + ' ' + arrName[0]
}
  1. Click Verify to run a test of the expression. If the expression is valid, click Apply.
The Label Class pane with the parameters to be filled

The map with the newly configured labels after applying the Arcade expression is shown below.

The map with the newly configured labels in ArcGIS Pro

Article ID: 000031040

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 9x

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