Power Automate Split Function Explained With Examples

Power Automate Split Function Explained With

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.

Syntax

split('<text>', '<delimiter>')

Input parameters

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

Return value

  • 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:

decodeUriComponent('%0A')

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"]
Power Automate split by new line
Power Automate Split by new line

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
Power Automate Split and get first element
Power Automate Split and get first element

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 with the Power Automate trim function.

Let’s start!

  1. Add an Initialize variable action and set Name=result and Type=Array
  2. 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.
Power Automate Split and trim 1

Now add an Initialize variable action and set Name=split,Type=Array and Value=

split(variables('myText'),decodeUriComponent('%0A'))
Power Automate Split and trim 2

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=

trim(item())
Power Automate Split and trim 3

When you do a test run you will see that result has the value:

["John","Sally","Mike"]

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"]

Split backslash

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 length function to get the array size.

length(split('a,b,c',','))
=> 3

4 thoughts on “Power Automate Split Function Explained With Examples”

  1. I believe this:
    split(‘a\b\c’,’\’)
    => [“a”,”b”,””c]

    should be:
    split(‘a\b\c’,’\’)
    => [“a”,”b”,”c”]

Leave a Comment

Your email address will not be published. Required fields are marked *