操作方法

操作方法:在 ArcGIS Pro 中从属性表中的字符串字段的值中移除空格

Last Published: April 15, 2024

描述

在 ArcGIS Pro 中,有时需要从属性表中的字符串字段的值中移除多余的空格。 这可以使用 strip() Python 函数来实现,该函数可以移除任何字符(包括空格)。 本文介绍了在“计算字段”工具中使用 strip() Python 函数移除空格的工作流。

在本例中,移除了 COUNTY 字段的值中的多余空格以统一格式。

属性表中的 COUNTY 字段。
Note:
• The strip() function removes all leading and trailing characters mentioned in the argument. If no argument is presented, only spaces are removed.
• To remove either leading or trailing spaces, use the lstrip() or rstrip() functions respectively.
• This function only works on string and text fields, not integer fields.

解决方案或解决方法

  1. 打开 ArcGIS Pro 工程。
  2. 内容窗格中,右键单击该图层并单击属性表以打开该图层的属性表。
显示“属性表”选项的“内容”窗格。
  1. 在属性表中,右键单击包含要移除空格的值的字段名称,然后单击计算字段。 本例中使用了 COUNTY 字段。
显示“计算字段”选项的 COUNTY 字段。
  1. 计算字段窗口中配置参数。
  1. 对于输入表,确保已预先填充在步骤 2 中选择的图层。 在本例中,输入表为 Petroleum_Well
  2. 对于字段名称,确保已预先填充在步骤 3 中选择的字段。 否则,请从下拉菜单中选择该字段。 在本例中,字段名称为 COUNTY。
  3. 对于表达式类型,选择 Python 3
  4. 对于表达式,在表达式框中键入以下提供的代码。 将“字段名称”替换为在步骤 3 中选择的字段的名称。
!Field Name!.strip()
Note:
The Calculate Field tool changes the input data permanently. To enable undo, toggle the Enable Undo option on in the Calculate Field window before running the tool. Or, create a new field and configure the field.
“计算字段”窗口
  1. 单击确定

将从 COUNTY 字段的值中移除空格。

属性表中的 COUNTY 字段。

文章 ID: 000028712

接收通知并查找新问题或常见问题的解决方案

从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

下载 Esri 支持应用程序

相关信息

发现关于本主题的更多内容

获取来自 ArcGIS 专家的帮助

联系技术支持部门

下载 Esri 支持应用程序

转至下载选项