PowerApps 中的 Trim 與 TrimEnds 函式Trim and TrimEnds functions in PowerApps

從文字字串中移除多餘的空格。Removes extra spaces from a string of text.

說明Description

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.

語法Syntax

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.

範例Example

公式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.

注意

如果您藉由按一下或點選 [檔案] 功能表上的 [集合] 來顯示集合,則不會出現多餘的空格。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.