How to Use Power Automate trim() Function?

I was working on a Power Automate project recently, where I got one scenario to clear the spaces from the beginning of text input.

For this, Power Automate has a string function called the ‘trim()‘ function to remove the spaces.

In this article, I will introduce the Power Automate trim() function and syntax. Finally, I will show you how to use the Power Automate trim() function with an example.

The Power Automate trim() function eliminates leading and trailing spaces from a given text string.

Power Automate trim() Function

The power Automate trim() function removes all the leading and trailing spaces from a provided text string. This means it clears out spaces that are present at the beginning and end of a text.

However, it does not remove the spaces that are included in between the text string.

Example:

TextOutput
“  United States of America ““United States of America“

Here, it removes the first and last space from the given string.

Refer to the image below:

Power Automate trim() function

This is a brief description of the Power Automate trim() function.

Power Automate trim() Function Syntax

Here is the syntax for the Power Automate trim() function in the below code.

trim(['text string'])

Parameter:

  • text string: The string that should be trimmed.

Return Value:

The datatype returned will be in the form of a string without leading and trailing spaces.

Example:

  • trim(‘ XYZ ‘) => Returns output as exact text after removing beginning and end spaces, i.e., ”XYZ”.
  • trim(‘ ABC def ‘) => Returns output as “ABC def” -> It does not remove space in between characters.

This briefly introduces the Power Automate trim() function syntax.

How to Use Power Automate trim() Function

I will show you how to use the Power Automate trim() function in an Instant cloud flow.

Follow the below step-by-step process to create a Power Automate flow that will trigger manually.

Example:

In this scenario, I want to remove leading whitespaces from a given text string.

I have taken a string with a value like ” Qualcomm is an American Multinational corporation.”

Text InputOutput
“ Qualcomm is an American Multinational corporation ““Qualcomm is an American Multinational corporation”
Power Automate trim() function expression

To work around this, follow the below given steps.

1. Navigate to the Power Automate home page -> Select +Create -> Click on Instant cloud flow -> Set flow name -> Choose Manually trigger a flow -> and click on Create.

  • Click on +Add an input -> Select Text.
Power Automate trim() Function syntax

2. Then, add an Initialize variable flow action and set the details below.

  • Name: Provide a name for an initialized variable.
  • Type: Select datatype from the drop-down menu.
  • Value: Take a Text input from dynamic content.
trim() function expression in Power Automate

3. In this step, add a “Compose” flow action to provide a trim function expression.

  • Inputs: Add the below expression given in the code.
trim(variables('Text'))
How to use trim() function expression in Power Automate

4. After building a flow, Save it and Test the flow. In the Runflow box, give the text input to test the trim function manually.

trim() function format in Power Automate

5. When the flow runs successfully, it will display the compose outputs returned with text string without any spaces at the starting and ending of a text.

Microsoft Power Automate trim() function

This is how to use the Power Automate trim() function to remove the spaces at the start and end of a text string.

Conclusion

This Power Automate tutorial aims to help you eliminate spaces at a string’s starting and ending position using the Power Automate trim() function.

I have covered the topics below:

  • Power Automate trim() function syntax
  • Example of using Power Automate trim() function within an instant cloud flow.

Also, you may like some more Power Automate tutorials:

>