To trim spaces from string the Power Automate trim function is the right choice. The trim function removes all leading and trailing spaces from your text. It does not remove whitespace that is surrounded by characters.
Power Automate Trim Function
The Power Automate trim function returns a string, where leading and trailing whitespace is removed.
Syntax
trim('<text>')
Input parameters
- text (mandatory): The string that should be trimmed (removal of leading and trailing whitespace).
Return value
- The given string without leading and trailing whitespace.
Power Automate Trim Expression Examples
trim(' abc ')
=> "abc"
trim('abc')
=> "abc"
trim(' abc def')
=> "abc def"
How To Use The Trim Function In Power Automate
In this how to you will learn, how to trim a variable in Power Automate. You will learn how to use the Trim function to transform ‘ Hello, Joe! ‘ to ‘Hello, Joe!’.
-
Create a new flow, give it a name (1), select ‘Manually trigger a flow’ (2) and click ‘Create’ (3)
Create a new flow
-
Add a new Initialize variable step: Search for ‘initialize’ (1) and select the ‘Initialize variable’ action (2)
Add Initialize variable step
-
Configure Initialize variable action: Name = ‘text’ (1), Type = ‘String’ (2) and Value = ‘ Hello, Joe! ‘ (3)
Set up variable text
-
Add a compose step: Search for ‘compose’ (1) and select ‘Compose’ (2)
Add a compose step
-
Configure Compose Action: Click into Inputs input field (1) and enter ‘trim(variables(‘text’))’ in the expression editor (2) and click ‘Update’
Trim function in Power Automate flow
-
Do a test run
Check result without spaces