Trim and TrimEnds functions
Applies to: Canvas apps Dataverse formula columns Desktop flows Model-driven apps Power Pages Power Platform CLI
Removes extra spaces from a string of text.
Description
The Trim function removes all spaces from a string of text except for single spaces between words.
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.
By trimming spaces between words, Trim is consistent with the function of the same name in Microsoft Excel. However, TrimEnds is consistent with programming tools that trim spaces only from the start and end of each string.
Syntax
Trim( String )
TrimEnds( String )
- String - Required. The string of text to remove spaces from.
Trim( SingleColumnTable )
TrimEnds( SingleColumnTable )
- SingleColumnTable - Required. A single-column table of strings to remove spaces from.
Example
Formula | Description | Result |
---|---|---|
Trim( " Hello World " ) | Removes all spaces from the start and end of a string and extra spaces from within the string. | "Hello World" |
TrimEnds( " Hello World " ) | Removes all spaces from the start and end of a string. | "Hello World" |
The following examples use a single-column collection, named Spaces, that contains these strings:
Value |
---|
" Jane Doe " |
" Jack and Jill" |
"Already trimmed" |
" Venus, Earth, Mars " |
"Oil and Water " |
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 " ] )
Formula | Description | Result |
---|---|---|
Trim( Spaces ) | Trims all spaces from the start and end of each string and extra spaces from within each string in the Spaces collection. | A single-column table with a Value column containing the following values: "Jane Doe", "Jack and Jill", "Already trimmed", "Venus, Earth, Mars", "Oil and Water" |
TrimEnds( Spaces ) | Trims all spaces from the start and end of each string in the Spaces collection. | A single-column table with a Value column containing the following values: "Jane Doe", "Jack and Jill", "Already trimmed", "Venus, Earth, Mars", "Oil and Water" |
Note
Extra spaces don't appear if you display a collection by clicking or tapping Collections on the File menu. To verify string length, use the Len function.