Working With Power Automate Strings In 12 Examples

Power Automate Strings

Knowing how to use strings is essential in every programming environment. Power Automate strings are no exception to this. Unfortunately, working with String within Power Automate is a little more complicated than in most programming languages. In most cases we need to use Power Automate expressions, which are not always that intuitive. With this article I try to demonstrate solutions for common use cases. Since I’m learning myself, please feel free to let me know, if there is a better solution.

12 Power Automate String Manipulation Examples

There is a set of operations you need to know to successfully work with strings. You need to know how to concatenate strings, join strings, split strings, convert strings and more. The following examples will show you how to solve these tasks with Power Automate.

Let’s get to know Power Automate string functions to solve common problems.

Concatenate strings

When you want to append on string to another, you can use the Concat function like shown below:

 concat(variables('a'),variables('b'))
power automate concatenate string

Join strings

Converting an array of strings into one string by appending all items with seperator can be achieved with the Join function. In the example below a ‘,’ is used to separate the items in the resulting string.

 join(variables('textArray'),',')
power automate join strings

Split string by delimiter

Having something like CSV line where different string values a separated by commas is common. Often you want to transfer the values into an array for further processing. To convert the line to an array you can use the Power Automate split string function like shown in the example below.

 split(variables('colors'),',')
power automate split string by delimiter

Replace multiple strings

When you have a text and want to replace multiple strings with one string. For instance you want to replace orange, apple and banana with fruits like this:

I like orange, apple and banana. => I like fruits, fruits and fruits.

You can do this with nested replace functions:

 replace(replace(replace(variables('Text'),'orange','fruits'),'apple','fruits'),'banana','fruits')

But this gets quickly hard to maintain with a large number of replace calls. Here is a way to replace the items in a loop.

This will be the function to replace the strings:

 replace(variables('Text'),item(),'fruits')

This is the flow to replace the strings.

power automate replace multiple strings

Append string new line break

For Power Automate strings there is no standard way of integrating line breaks. In many other programming languages it is common to use ‘\n’ which is not working for Power Automate. You simulate this solution in the following way.

 replace('a\nb','\n',decodeUriComponent('%0A'))
Power Automate remove characters from a string
Power Automate remove characters from a string

Remove characters from a string

To remove characters from a string in Power Automate you can simply replace them by an empty string.

To remove multiple characters in one Power Automate expression you can nest multiple replace function calls.

In the example below we remove the brackets of the string “(100)”:

  replace(replace('(100)','(',''),')','')

String begins with

Want to check if a string begins with a certain string? Use the startsWith function:

 startsWith('abc','a')

String ends with

Want to check if a string ends with a certain string? Use the endsWith function:

 endsWith('abc','c')

Contains

TO find out if one strings contains the other, use the Contains function as shown.

 contains('abc','b')

Get string length

Getting a Power Automate string’s size can be achieved with the Length function.

See the Power Automate length of string example below:

 length('my string')

String remove last character

To remove the last character of a string, you need three functions:

  • Substring to define the new string
  • Length to get the number of characters your string has
  • Sub to subtract the one character from the string length to provide substring which is the last character
 substring(variables('Text'),0,sub(length(variables('Text')),1))

String to number

When you need to convert a Power Automate string to integer, you can use the int function.

This is how Power Automate converts a string to an integer:
 int('010')  // Power Automate convert string to integer

Leave a Comment

Your email address will not be published.