By using split in Power Automate you can convert a string into an array by defining a delimiter.
A classic example is comma separated data in a string. The Power Automate split function returns an array with the data which can be further processed.
In this article we explain how to use the Power Automate split function and show many examples for common use cases of the split function.
Power Automate Split Function
The Power Automate split function splits a string into an array by a given delimiter.
- text (mandatory): The string that needs by split into an array by the given delimiter.
- delimiter (mandatory): The delimiter that is used to separate the text in multiple parts.
- An array of strings that results on the splitting of the strings by the given delimiter. The delimiter is not part of the resulting strings.
Examples – Power Automate split expression
split('sally,john,lisa', ',') => ['sally','john','lisa'] split('sally,john,lisa', '#') => ['sally,john,lisa']
Power Automate Split Function Examples
I tried to collect some common tasks for the split function and show how to achieve them.
I hope you find something useful in these Power Automate split function expression examples.
Split by new line
To use a new line as a delimiter in a split function expression, you can decode the new line like this:
To split by new line use the decoded line break like this in the Power Automate split function expression:
split(variables('myText'),decodeUriComponent('%0A')) => ["a","b","c"]
Split and get first element
To get the first element of a Power Automate split expression result use the first function like shown below:
first(split('a,b,c',',')) => a
Split string apply to each: Split and trim
This Power Automate split function example shows how to use apply to each to process the result of a split function.
We will split a text by new line and then trim every item returned by the split expression.
- Add an Initialize variable action and set Name=result and Type=Array
- Add an Initialize variable action and set Name=myText, Type=String and Value should be multiple lines and lines should have some white spaces at the beginning and/or end of a line to see if the trim is working.
Now add an Initialize variable action and set Name=split,Type=Array and Value=
Now add an Apply to each with split as input and add an Append to array variable action to the Apply to each.
Set Name=result and Value=
When you do a test run you will see that result has the value:
Split attachment name
To use the Power Automate split function to split an attachment name, just use the dot as a delimiter.
split('text.pdf','.') => ["text","pdf"]
Split email address
To use the Power Automate split function to split an email address, just use the @ as a delimiter.
split('[email protected]','@') => ["joe","email.com"]
Split by space
To split a string with the split function by delimiter whitespace, take look at the example below.
split('a b c',' ') => ["a","b","c"]
To split a string with the split function by delimiter backslash, take look at the example below.
split('a\b\c','\') => ["a","b",""c]
Split length / split count
If you need to know how many elements the Power Automate split expression returned, simply use the lengtgh function to get the array size.
length(split('a,b,c',',')) => 3