How to remove first and last character(s) from a string in Power Automate

Reading the title of the blog you might be wondering – “Why this blog?”. After all trimming characters from a string is a mundane job and every language has a function to do that. With all the might that Power Automate has, there must be a trim function to perform the same operation in Power Automate.

If you have similar thoughts, you are partially correct. Power Automate do have trim function. Unfortunately the trim function just trim the spaces. So if you have double quotes to remove from the start and end, trim does not work.

To know more in detail about removing spaces from end as well as extra spaces within the text, you can follow my post here.

Coming back to the topic, what’s our option here?

While there is no direct option, using a combination of functions we can achieve this functionality. So let’s get started.

We have declared a variable as shown in the below screenshot.

We have double quotes (“) at the start and end of the string.

The target here is to remove the double quotes from the start and end. And the below expression should help.

substring(variables('VarX'), 1, sub(length(variables('VarX')),2))

We are basically using the substring function and then put the start index to 1 (to skip the quote at the beginning) and for length, we are taking total length – 2 since we are skipping two characters (first and last).

Remember in Power Automate operators are functions as well. So to minus you basically need to use the sub function.

Very simple but trust me if you are new to Power Automate, these small stuffs can eat into some of your productive time.

You may also like the below posts.

Hope this helped

Debajit Dutta
Business Solutins MVP