HOW TO
In ArcGIS Pro, Python expressions with multiple statements can be used to split and rearrange text strings of a field. The rearranged text strings can be used for data management or search results optimization. This article provides an example and instructions using Python expressions to split and rearrange text strings of a field for ArcGIS Pro.
The image below shows the Forest_Name field with the text string records.
Note: Refer to ArcGIS Pro: Calculate Field (Data Management) for more information on the parameters in the Calculate Field tool.
<function_name>(!<feature_name>!)
def sort_name(n): split = n.split()
if len(split) == 0: return ''
if len(split) < 2: return ('{0}').format(split[0])
elif len(split) < 3: return ('{0} {1}').format(split[1], split[0]) else: return ('{0} {1} {2}').format(split[1], split[2], split[0])
def sort_name(n): split = n.split() if len(split) == 0: return '' if len(split) < 2: return ('{0}').format(split[0]) elif len(split) < 3: return ('{0} {1}').format(split[1], split[0]) else: return ('{0} {1} {2}').format(split[1], split[2], split[0])
The image below shows the ForestBoundaryFullName attribute table with the updated field values and the name text rearranged.
Article ID: 000028839
Get help from ArcGIS experts
Download the Esri Support App