When it comes to parsing strings, there’s a lot of difficult things to take into consideration. For example, spaces in the beginning and the end of a string may be useless, but doing it manually is boring. That’s why we use the Power Automate trim function to remove leading and trailing whitespace from a string and return the updated string.

Let’s see how to use it efficiently.

Usage

It follows a simple pattern where we provide the string to trim. For example:

trim('  Manuel T. Gomes  ')

will return 

'Manuel T. Gomes'

That’s what we expect. So regardless of the number of spaces in the beginning or end, they will all be removed. But what about spaces in the middle of the string? For example:

trim('  Manuel       T. Gomes  ')

will return 

'Manuel       T. Gomes'

Removing only the trailing and leading characters is a big difference from Power Apps’ trim function, where the spaces in the middle of the string will be removed. In our case, the spaces won’t be removed.

Limitations

Although there’s no documented limitation for the limit of characters, I would recommend not going over 10000 characters. However, if you’re parsing huge strings, it doesn’t make sense to break them since the trim won’t return the correct values, but be sure to deal with errors if your Flow fails.

Recommendations:

Here are some things to keep in mind.

Convert Actions

Power Automate trim function is the kind of function that doesn’t hurt to use. What I mean is that worst-case scenario, your input and output strings will be the same. If you’re converting text to another type, I recommend always trim the string before converting it, especially if the user provides the string. A space can break a conversion, so using the trim will remove these issues from the start.

Don’t nest

There’s no real reason to do it, but if you find yourself in a situation where you have nested the Power Automate trim function in a formula, you should review it and make everything more straightforward.

Sources:

Microsoft’s trim Function Reference

Back to the Power Automate Function Reference.

Photo by Thom Holmes on Unsplash

Manuel Gomes

I'm a Project Manager with experience in large projects and companies. I've worked in the past for companies like Bayer, Sybase (now SAP) and I'm currently working for Pestana Hotel Group.

View all posts by Manuel Gomes →

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: