How to split a string into an array in Power Automate?

In this Power Automate tutorial, we will be looking at how to split a static/dynamic string value into an array in Power Automate. We will also be discussing the below points.

  • How to split string in Power Automate
  • Split string by comma in Power Automate
  • How to split string by space in Power Automate
  • Split string between two characters in Power Automate
  • How to get string from array in Power Automate
  • Power Automate split string into array
  • Split string into array line break/new line in Power automate
  • Split string into array and loop in Power Automate
  • How to split string into array get first element in Power Automate
  • Split string into array get last element in Power Automate
  • Power Automate split string into array by character
  • How to parse string to array get a specific element in Power Automate

Introduction Power Automate split string

While working on a Power Automate flow, many a time, we are required to split a static/dynamic string value, to achieve any such requirement we use split() function of power automate.

The split() function breaks a string value into a list of substrings. We use the split() function to break up commas, space, specific delimiter, slash, etc.

A delimited or separator is used to break the text string apart. The separator can be an integer or characters that are matched as a whole string.

Syntax of Split() function:

split( text: string, separator: string)

Power Automate split string by comma

Let’s start by learning how to split a string value by a comma in Power Automate.

In this example, we will create a Power Automate flow which will get manually triggered.

Manually Trigger a flow
Manually Trigger a flow

We will click on ‘Add Step’ and from choose an operation, we will initialize a variable “teststring” and set the variable teststring with a static value “Delhi, Mumbai, Chennai, Kolkata”.

Initialize teststring variable
Initialize teststring variable

Once our variable is initialized, we will compose the input by selecting the Compose action in flow and then pass the output of the compose action to an email body in Send an email action.

Power Automate split string by comma
Power Automate split string by comma

Here we are composing the input by using the split() function by passing the variable ‘teststring‘ and separator as ‘,’. And using the output of the compose action in our email body of the Send an email action.

Here is the expression:

split(variables('teststring'),',')
Power Automate split string by comma result
Power Automate split string by comma result

After manually running the flow, we will receive the above email with the string value as shown in the fig above, and this is how to split string by commas in Power Automate.

Read Power Automate formatdatetime

Power Automate split string by space

In the above example, we have seen how to split string by comma in Microsoft flow. Let’s use the same example to split the string by space in Power Automate.

We will again initialize our variable “teststring” and set the value. We will compose the input using split() function and will use the compose action output in the email body in Send an email action.

Power Automate split string by space
Power Automate split string by space

Here we are setting the “teststring” variable with a value like the above pics which is separated by space. Then we are using the split() function with ‘space’ separator. We are then using the output in our email body.

Here is the expression:

split(variables('teststring'),' ')
Power Automate split string by space result
Power Automate split string by space result

After manually running the flow, we will receive the above email with the string value as shown above diagram. And this is how we can split string by space in Power Automate.

Power automate split string between two characters

Let’s see how to split a string value between two different characters in Power Automate. This can be a bit more complex to achieve in Power automate flow.

Suppose, there is a requirement to get the substring between two characters ‘@‘ and ‘|‘ from a string value “sam@infotech|com” or any dynamic value to either populate a SharePoint field or send an email with the substring value

Here we have already initialized our variable “teststring” and have set the value as “sam@infotech|com”. We will use compose action to get the index of both characters. And then by using the substring() function, we will get the required substring and use the same in the email body.

Power automate split string between two characters
Initialize variable

Here we are using 4 compose actions in our flow to get the index of “@” and “|”, and then using these indexes to get the substring “Infotech” by using the substring() function.

split string between two characters in Power automate
Compose actions in flow

At first, we will find the position of “@” and “|” by using indexof() function and we will pass the same to our first compose action in the flow.

how to split string between two characters in Power automate
Compose Index Function 1

Here, we will get the index of “@” on the variable “teststring” and then add 1 to the resulting index integer, this sum will return the position of “@”.

Here is the expression:

add(int(indexOf(variables(teststring), '@')), 1)

Then with our second compose action, we will get the index of “|”.

split string between two characters in Power automate
Compose Index Function 2

This expression will result the integer value of the indexof() function with position detail of “|”. But, here we are not using add expression.

Here is the expression:

int(indexOf(variables('teststring'), '|'))

In the third compose action, we will try to get the number of characters between “@” and “|”.

Compose LastIndex
Compose LastIndex

Using this expression, we will get the count of characters between both “@” and “|” characters.

Here is the expression:

sub(outputs('Indexof_|'),outputs('Indexof_@'))

Finally, we have everything required for the substring() function. We got the index of “@”, the count of characters between both the characters.

Final Compose action
Final Compose action

In this expression, we are passing the parameters for substring() function which are the variable “teststring“, the output of the index of “@” and finally the count of characters between “@” and “|”.

Here is the expression:

substring(variables('teststring'),outputs('Indexof_@'),outputs('LastIndex'))
Power automate split string between two characters result
Power automate split string between two characters result

After passing the output of the final compose action to the email body, we will receive the above email with the substring value as “infotech“.

This is how you can split any string between characters in power automate.

Read How to use Rest API in Power Automate

Power automate get string from array

Before we learn how to split string into array in Power Automate, let’s see how can we get string from array in Power Automate.

Suppose we got a SharePoint list column with multiple choices and we need to send an email with the column value. We need all the items at once, we don’t want to loop through the items as we don’t want to send multiple emails.

We want all of the value of the choice at once, in a single readable format. The main goal here is to not loop the values and convert the values to a single string.

Power automate get string from array
SharePoint list

To achieve this we have pre-initialized the variable “teststring” and we have added the Get Items SharePoint action to retrieve the cities column values.

Note: Power Automate will automatically add “Apply to each” action once we try to use any dynamic content from an array.

Power Automate get string from array
Power Automate get string from array

Using the “Apply to each” action, we are appending each value of the cities column to our “teststring” variable to make a readable string format. And we are passing the same variable in our email body to send an email.

Power Automate get string from array result
Power Automate get string from array result

Once, we save and run the flow, we will receive the above email with the value in string format and this is how we can get string value from any dynamic/static array in Power Automate.

Power Automate split string into array

Let’s see how can we split string into array in Power Automate.

Once again we will initialize our variable “teststring” in Power Automate Flow with a string value and we will use compose action to split the string into an array with split() function. And then send the output of the compose action in the email body.

Power Automate split string into array
Power Automate split string into array

In this expression, we are splitting the string with “empty space” separator and then converting it into a collection.

Here is the expression:

split(variables('teststring'),' ')
Power Automate split string into array result
Power Automate split string into array result

Once we run the flow, we will receive the variable value in array format. This is how we can split a string into Array in Power Automate.

Read Power Automate Trigger Conditions

Power Automate split string into array line break/new line

In the above example, we have seen how to split a string into an array, Let’s now see how to split strings values into an array with line breaks in Power Automate.

Here we will select the initialize variable action in the Power Automate flow and we will set the variable “teststring” as string datatype and provide the value with line breaks as shown in the below image.

Power Automate split string into array line break/ new line
Power Automate split string into array line break/ new line

Here to use the line break as a delimiter in a split() function, we use the decodeUriComponent(‘%0A’) function.

Here is the expression:

split(variables('teststring'),decodeUriComponent('%0A'))
Power Automate split string into array line break result
Power Automate split string into array line break result

After running the flow, we will receive the above email with an array value and this is how we can split string with line breaks into an array in Power Automate.

Power Automate split string into array and loop

Now, let’s learn how can we split string value into an array and use each loop in Power Automate.

Suppose we have a multiple-choice SharePoint column with cities name or any static value and we need to send an email for each value.

At first, we will use the compose action to set the input shown below. We can also use any dynamic value. Here we are setting a static string value.

Compose Action
Compose Action

After this, we will initialize a variable “testarray” with array datatype and use to split() function to separate the string values from the character “|” as shown in the below image.

Power Automate split string into array and loop
Power Automate split string into array and loop

Here is the expression:

split(outputs('Compose'),'|')

We have the city names in an array format in our variable, we will now use Apply to each control to loop each item in the variable “testarray” and add Send an email action inside the loop to send an email with the current city value.

Once we run the flow, we will receive 4 different emails with each city name and this is how you can loop split string into array in Power Automate.

Read Power Automate IF Expression

Power Automate split string into array get first element

To get the first element of an array by splitting a string value in Power Automate, we will be using the first() function of Power Automate.

Power Automate split string into array get first element
Power Automate split string into array get first element

Here we will first initialize the variable “teststring” with string value separated by commas. So we will use the split() function to get the required array of cities and then we will use compose action to get the first element of the array and then we will send the output of this action in the email body.

Here is the expression:

first(split(variables('teststring'),','))
Power Automate split string into array get first element result
Power Automate split string into array get first element result

After running the flow, we will receive an email with the city name as highlighted above which is the first element of the array and this is how we can get the first element of array in Power Automate.

Power Automate split string into array get last element

Similar to the above example, we can also get the last element of the array in Power Automate.

To get the last element of an array by splitting a string value in Power Automate, we will be using the last() function of Power Automate.

Power Automate split string into array get last element
Power Automate split string into array get last element

We are using the pre-initialized variable “teststring” in the above example with string values separated by commas. We will use the split() function to get the required array of cities and then we will use compose action to get the last element of the array and then we will send the output of this action in the email body.

Here is the expression:

last(split(variables('teststring'),','))
Power Automate split string into array get last element result
Power Automate split string into array get last element result

And this is how we can split a string value array to get the last element in Power Automation.

Read Power Automate Multiple Conditions

Power Automate split string into array by character

Let’s see another example to split a string value into an array by character in Power Automate.

We are using a power automate flow, which will get manually triggered. At first, we will initialize a variable “teststring” with string datatype and value as shown in the below image.

Power Automate split string into array by character
Power Automate split string into array by character

Then we will compose action to split the string by “@” character and then send the output of this action to an email body.

Here is the expression:

split(variables('teststring'),'@')

After manually running the flow, we will receive the below email with array value.

Power Automate split string into array by character result
Power Automate split string into array by character result

And this is how we can split string into an array by character in Power Automate.

Read Power Automate Parallel Branch with Examples

Power Automate parse string to array get a specific element

In this last example of this tutorial, let’s learn to split string into an array to get a specific element in Power Automate.

Just like our previous examples, we will be using the pre-initialized variable “teststring” and a compose action to achieve the same. Here, we will see how to get “chennai” in our email from the array of city strings.

Power Automate parse string to array get a specific element
Power Automate parse string to array get a specific element

We will be using the split() function to get an array of city names from the variable “teststring” and then in the square bracket, we are trying to get the number of city “Chennai”. An integer number after an array will select the respective time from the list starting at 0.

Here is the expression:

split(variables('teststring'),',')[sub(max(length(split(variables('teststring'),',')),4),2)]
Power Automate parse string to array get a specific element result
Power Automate parse string to array get a specific element result

After triggering the flow, we will receive the above email with city value as shown above and this is how you can get any specific element value from array in Power Automate.

In this tutorial, we have covered all the different ways to split strings to get an array in Power Automate. Here are the examples we have discussed above:

  1. Introduction Power Automate split string 
  2. Power Automate split string by comma
  3. Power Automate split string by space
  4. Power automate split string between two characters
  5. Power automate get string from array
  6. Power Automate split a string into an array
  7. Power Automate split a string into array line break/ new line
  8. Power Automate split a string into array and loop
  9. Power Automate split a string into array get first element
  10. Power Automate split a string into array get last element
  11. Power Automate split strings into array by character
  12. Power Automate parse string to array get a specific element

You may like the following Power Automate tutorials:

>