PowerApps 中的 Trim 和 TrimEnds 函数Trim and TrimEnds functions in PowerApps

从文本字符串中删除多余空格。Removes extra spaces from a string of text.


Trim 函数可删除文本字符串中的所有空格,单词之间的单个空格除外。The Trim function removes all spaces from a string of text except for single spaces between words.

TrimEnds 函数可删除文本字符串开头和结尾的所有空格,但保留单词之间的空格。The TrimEnds function removes all spaces from the start and end of a string of text but leaves spaces between words intact.

如果指定单个文本字符串,则任一函数的返回值均为删除了所有多余空格的字符串。If you specify a single string of text, the return value for either function is the string with any extra spaces removed. 如果指定包含字符串的单列表格,则返回值为修整的字符串的单列表格。If you specify a single-column table that contains strings, the return value is a single-column table of trimmed strings. 如果你有多列表,可以将其调整为单列表,如使用表中所述。If you have a multi-column table, you can shape it into a single-column table, as working with tables describes.

通过修剪单词之间的空格,Trim 与 Microsoft Excel 中相同名称的函数一致。By trimming spaces between words, Trim is consistent with the function of the same name in Microsoft Excel. 但是,TrimEnds 与仅修剪每个字符串开头和结尾空格的编程工具一致。However, TrimEnds is consistent with programming tools that trim spaces only from the start and end of each string.


Trim( String )Trim( String )
TrimEnds( String )TrimEnds( String )

  • String - 必需。String - Required. 要从中删除空格的文本字符串。The string of text to remove spaces from.

Trim( SingleColumnTable )Trim( SingleColumnTable )
TrimEnds( SingleColumnTable )TrimEnds( SingleColumnTable )

  • SingleColumnTable - 必需。SingleColumnTable - Required. 要从中删除空格的字符串的单列列表。A single-column table of strings to remove spaces from.


公式Formula 说明Description 结果Result
Trim( "   Hello     World   " )Trim( "   Hello     World   " ) 删除字符串开头和结尾的所有空格,并删除字符串内的多余空格。Removes all spaces from the start and end of a string and extra spaces from within the string. “Hello World”"Hello World"
TrimEnds( "   Hello     World   " )TrimEnds( "   Hello     World   " ) 删除字符串开头和结尾的所有空格。Removes all spaces from the start and end of a string. “Hello     World”"Hello     World"

以下示例使用名为 Spaces 的单列集合,其中包含下列字符串:The following examples use a single-column collection, named Spaces, that contains these strings:

若要创建此集合,请将按钮控件的 OnSelect 属性设置为以下公式,打开“预览”模式,然后单击或点击按钮:To create this collection, set the OnSelect property of a Button control to this formula, open Preview mode, and then click or tap the button:
ClearCollect( Spaces, [ "   Jane   Doe   ", "    Jack   and   Jill", "Already trimmed", "   Venus,   Earth,   Mars  ", "Oil and Water   " ] )ClearCollect( Spaces, [ "   Jane   Doe   ", "    Jack   and   Jill", "Already trimmed", "   Venus,   Earth,   Mars  ", "Oil and Water   " ] )

公式Formula 说明Description 结果Result
Trim( Spaces )Trim( Spaces ) 修剪 Spaces 集合中每个字符串开头和结尾的所有空格,以及该集合中每个字符串内的多余空格。Trims all spaces from the start and end of each string and extra spaces from within each string in the Spaces collection.
TrimEnds( Spaces )TrimEnds( Spaces ) 修剪 Spaces 集合中每个字符串开头和结尾的所有空格。Trims all spaces from the start and end of each string in the Spaces collection.

请注意:如果通过在“文件”菜单上单击或点击“集合”来显示集合,则不会出现多余的空格。Note: Extra spaces don't appear if you display a collection by clicking or tapping Collections on the File menu. 若要验证字符串长度,请使用 Len 函数。To verify string length, use the Len function.