String Functions in Power Automate
π§ String Functions in Power Automate
String functions in Power Automate provide powerful tools for manipulating text values. Whether youβre combining text, extracting parts of a string, or transforming input data, these functions help you streamline complex flows and clean data dynamically.
Mastering string functions in Power Automate is essential for building reliable flows that work with user input, emails, file paths, and external data sources like SharePoint, Dataverse, or HTTP APIs.
π Common String Functions in Power Automate
The table below highlights the most widely used string functions in Power Automate. Each function includes a purpose, syntax, and a real-world example.
Function | Purpose | Syntax | Example | Output |
---|---|---|---|---|
concat() |
Joins two or more strings | concat(string1, string2) |
concat('Hello ', 'World') |
Hello World |
substring() |
Extracts a portion of a string | substring(string, startIndex, length) |
substring('PowerAutomate', 0, 5) |
Power |
replace() |
Replaces one substring with another | replace(text, old, new) |
replace('abc123', '123', 'XYZ') |
abcXYZ |
toLower() |
Converts text to lowercase | toLower('ABC') |
abc |
abc |
toUpper() |
Converts text to uppercase | toUpper('power') |
POWER |
POWER |
trim() |
Removes leading and trailing whitespace | trim(string) |
trim(' hello ') |
hello |
length() |
Returns the length of a string | length('Power') |
5 |
5 |
split() |
Splits a string into an array by a delimiter | split(string, delimiter) |
split('a,b,c', ',') |
['a','b','c'] |
indexOf() |
Returns the position of a substring | indexOf('abcde', 'c') |
2 |
2 |
lastIndexOf() |
Finds last occurrence of a substring | lastIndexOf('abcabc', 'a') |
3 |
3 |
π‘ Advanced String Functions for Power Users
For more complex flows, Power Automate offers advanced string functions:
Function | Purpose | Example | Output |
---|---|---|---|
startsWith() |
Checks if string starts with a value | startsWith('PowerAutomate', 'Power') |
true |
endsWith() |
Checks if string ends with a value | endsWith('report.pdf', '.pdf') |
true |
contains() |
Checks if string contains a value | contains('hello world', 'world') |
true |
equals() |
Compares two strings (case-sensitive) | equals('abc', 'ABC') |
false |
guid() |
Generates a unique identifier | guid() |
e.g., 4e7b9d... |
π οΈ Practical Examples Using String Functions
1. Format a File Name with Current Date
concat('Invoice_', formatDateTime(utcNow(), 'yyyyMMdd'), '.pdf')
Output: Invoice_20250807.pdf
2. Clean and Capitalize User Input
toUpper(trim(replace(triggerBody()?['comment'], '\n', ' ')))
Use Case: Clean up form comments before sending in an email.
3. Extract Domain from Email Address
split(triggerBody()?['email'], '@')[1]
Output (from ‘user@company.com‘): company.com
β Best Practices for Using String Functions in Power Automate
- Use
trim()
to clean user input before further processing. - Combine
split()
andindexOf()
cautiously when extracting substrings. - Use
coalesce()
to prevent errors when strings may be null or empty. - Avoid hardcoding indexes unless the format is guaranteed.
- Break down complex expressions into multiple Compose actions for readability.
π« Common Mistakes and How to Avoid Them
Mistake | Issue | Fix |
---|---|---|
Hardcoded substring indexes | Can break if input varies | Use indexOf() or split() instead |
Null reference errors | Missing or empty values | Use coalesce(value, 'default') |
Wrong delimiter in split() |
Unexpected array result | Inspect actual input data before splitting |
Nested functions too complex | Hard to read & debug | Use multiple Compose steps and name them clearly |
Would you like a downloadable function reference sheet or should I continue with the next section, such as βDate and Time Manipulation in Power Automateβ?