To split a string in Power Automate, use the split() expression in a Compose or variable action, or use the Split data operation action in the UI. The split() function takes the string and a delimiter (like a comma or space) and returns an array of substrings.
Why You Need to Split Strings
Power Automate frequently receives text data that contains multiple values in one field. For example, a SharePoint list might store tags as “red;green;blue”, an email body might contain a list of names separated by new lines, or an API response might return a comma-separated string. Splitting converts that single text into an array, which you can then loop through, filter, or use in other actions.
Method 1: Using the split() Expression
The most direct way is the split() expression. It works in any action that accepts expressions, like Compose, Set variable, or Apply to each.
Syntax: split('
Example: To split “apple,banana,cherry” by comma, use:
split('apple,banana,cherry', ',')
This returns an array: ['apple', 'banana', 'cherry']. You can also use a variable or dynamic content as the first argument. For instance, if you have a string variable named myString, use split(variables('myString'), ',').
Method 2: Using the Data Operation “Split” Action
If you prefer a visual interface, use the Split action under Data Operation in the connector list. It has two fields: Input (the string) and Delimiter (the character or characters to split on). The output is an array. This action is essentially a wrapper for the split() function, so the result is identical.
Choosing the Right Delimiter
The delimiter can be any character or sequence of characters. Common choices include:
- Comma:
,for CSV-style data - Semicolon:
;for lists where commas appear in items - Space:
' 'to split words - Newline:
\nfor line breaks (note the backslash) - Pipe:
|for structured text
Be careful with special characters. In expressions, if your delimiter is a backslash, you need to escape it as \\. For example, to split on a backslash, use split('a\\b', '\\'). The same applies to quotes: use '' inside the expression to represent a single quote.
Handling Empty Strings and Edge Cases
If the input string is empty, split() returns an array with one empty string, not an empty array. This can cause unexpected behavior in loops. To avoid this, add a condition before splitting: if(empty(variables('myString')), array(), split(variables('myString'), ',')). The array() function creates an empty array.
Also, if the delimiter appears consecutively, the resulting array will contain empty strings. For example, split('a,,b', ',') returns ['a', '', 'b']. You can filter these out later with a filter() expression if needed.
Common Problems and Solutions
One frequent issue is splitting by newline. In a Compose action, you can use split(outputs('Compose_Text'), '\n') (with a literal backslash and n). If you copy the newline character from a text file, it may appear as an actual line break; in that case, use split(outputs('Compose_Text'), decodeUriComponent('%0A')) to represent the newline character.
Another problem is splitting a string that contains the delimiter inside quotes, like CSV files. The split() function does not respect quotes; it splits blindly. For CSV parsing, consider using the Parse CSV action (in the Text operations) or a custom connector, as it handles quoted fields correctly.
Frequently Asked Questions
Can I split a string into separate variables instead of an array? Yes. After splitting, you can use the first(), last(), or item() functions to access elements, or use an Apply to each loop to process each element individually. To store each element in a separate variable, you would need to loop and set variables, but that is rarely necessary.
How do I split a string by multiple delimiters? Power Automate does not have a built-in multi-delimiter split. You can replace all delimiters with one using the replace() function first. For example, to split by comma or semicolon, use: split(replace(replace(yourString, ',', ';'), ';;', ';'), ';') – but this is messy. A cleaner approach is to use a regular expression with the Regex action (if available) or a custom function.
What is the difference between split() and substring()? split() returns an array of substrings based on a delimiter. substring() extracts a single portion of a string based on start index and length. Use split when you need multiple pieces; use substring when you need one specific part.
Can I split a string in a condition? Yes, you can use the split() function inside a condition expression. For example, to check if a string contains a certain word, you can split by space and use contains() on the resulting array, or simply use contains() on the original string.
Why does my split return an array with one item when the string is empty? As mentioned, split('', ',') returns [''] because the empty string is considered a single element. If you want an empty array, use a conditional expression to handle the empty case.
Alternatives to split()
If you need to extract parts of a string based on a pattern, consider the substring(), indexOf(), or lastIndexOf() functions. For more complex parsing, you can use the Parse JSON action if your string is JSON, or the Compose action with a regular expression via the match() function (though limited). For CSV files, the Parse CSV action is more robust. For splitting a string into characters, you can use split(yourString, '') – this works and returns an array of single-character strings.
Related
- Speed and Intersection Safety Cameras: How They Work
- Traffic Light Reaction Time: How Long It Takes
- How to Export FileZilla Settings (Sites & Passwords)
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- How to Insert an Image in Excel From a Link in Microsoft 365To show an image from a link in Excel for Microsoft 365, put the image’s direct URL in…
- Excel Dropdown Limit to List: Setup, Limits, and FixesYes. In Excel for Microsoft 365 on Windows, use Data Validation to make a cell accept values from…
- Excel Named Range: How to Create and Use OneTo create a named range in Microsoft Excel for Microsoft 365 on Windows, select the cell or range,…
- Bi-Monthly Budget Template in Google Sheets: Setup GuideA bi-monthly budget template in Google Sheets can track income, planned spending, and actual expenses for each pay…
- COUNTIF Google Sheets Date Range: Formula, Examples & TipsTo count dates within a range in Google Sheets, use COUNTIFS with a start-date condition and an end-date…
- Change Date Format in Excel for the Web: Step-by-StepTo change a date’s appearance in Excel for the web, select the date cell or range, open Home…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.