Working With Power Automate Strings In 11 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.

11 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.

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'))

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'),',')

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 split function like shown in the example below.

 split(variables('colors'),',')

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.

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'))

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 strings size can be achieved with the Length function.

 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 charaters your string has
  • Sub to substract the one character from the string length to provide substring which is the last cahracter
 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.

 int('010')

Leave a Comment

Your email address will not be published.