Power Automate String Functions + 10 Examples

In Power Automate, you can work with converting and formating strings using string functions() and some of the collection functions.

In this tutorial, I will discuss how to deal with Power Automate string() functions with a few examples that include the below topics:

  • Concat () function
  • Substring() function
  • Length() function
  • Trim() function
  • Replace() function
  • Chunk() function
  • Startswith() function
  • Endswith() function
  • Tolower() function
  • Toupper() function
  • Lastindexof() function
  • Indexof() function
  • nthindexof() function
  • Split() function

Power Automate String Functions

The Power Automate string function converts strings and string characters, formats strings, and more.

Power Automate text functions are a basic technique that is extensively used to format data better or convert it to other sources.

So let’s discuss one by one.

Power Automate concat function

This is one of the Power Automate string functions, where it allows the combination of one or more strings and returns the combined string.

Syntax: concat('text1', 'text2', ...)

Example:

1. In Power Automate, select manually trigger flow. Take two text inputs as shown below:

Power Automate string functions

2. After that, add the Compose flow action and provide the concat() expression to combine the strings:

concat(triggerBody()?['text'],triggerBody()?['text_1'])
Power Automate string manipulation

3. Now save the flow. Click on Test -> Select Manually. In the Runflow window, provide details like First Name and Last Name -> Select Runflow.

Power Automate text functions

4. The body outputs of the compose action display the combined string, as shown below.

String functions in Power Automate

This is how to combine multiple strings using Power Automate string operations.

Power Automate Substring

To work with strings in Power Automate, you can use the substring() function, which returns the characters or a substring from a string based on position starting from zero.

Syntax: substring('text', startIndex, length)

Example:

1. Create Power Automate Instant cloud flow.

2. Next, select the Initialize variable action and set the variable as Name, Type as string, and provide Value.

Power Automate substring

3. After that, to get the substring from the provided string, enter the below given expression in the Compose Inputs section.

substring(variables('Name'),6)
Power Automate substring function

Output:

The below image represents the substring from a string in a Power Automate flow.

Text functions Power Automate

Power Automate Length of String

To count characters in a string using Power Automate, there is one useful function named the length() function that calculates and counts the number of characters in a string and the number of items in an array collection.

Syntax: length('string')
length([<collection>])

Example:

1. Here, you can initialize a string value that is required to determine its length. Provide a name for a variable, select the type as a string, and enter the value.

Power Automate count characters in string

2. To calculate a string’s length, provide the length() expression in the Compose flow action of the Power Automate flow.

length(variables('Greetings'))
Power Automate length of string

Output:

The Power Automate length() expression will return an integer number by counting characters in a string.

Power Automate string length

Power Automate Trim() Function

The Power Automate text functions include the trim() function, which helps remove spaces from the beginning and end of a string.

Syntax: trim('text')

Example:

1. Inside the Power Automate Manual trigger flow, take the text input.

Power Automate string operations

2. Add the Compose action and provide the trim() expression to eliminate the spaces.

trim(triggerBody()?['text'])
Power Automate trim string length

3. Then, save and run the flow. In the Run flow window, enter the string value with spaces. Click Runflow.

String functions Power Automate

Output:

As you can see in the image below, it will return the updated string, eliminating leading and trailing spaces.

String functions in Microsoft Power Automate

Power Automate Replace String

To do Power Automate string manipulation, like replacing characters from a string, one can use a case-sensitive replace() expression. This expression replaces a substring with a specified string and updates the resulting string.

Syntax: replace('text', 'oldText', 'newText')

Example:

1. Take an Initialize variable flow action, provide name, type, and value as shown in the below figure:

String manipulation Power Automate

2. Inside the Compose flow action, add the expression to replace the string characters.

replace(variables('Name'),'Lidia','Patti')
String function Microsoft Power Automate

3. When the flow runs successfully, you can check that the string has been replaced with a specific string, as shown in the image below:

String manipulation in Power Automate

Power Automate Chunk() Function

The string functions in Power Automate, like the chunk() function, will divide the string into equal halves based on the provided length. If the string remains with extra special characters, the remaining characters will also be considered one chunk.

Syntax: chunk('String', <length>)

Example:

Suppose I will take a word as Hello World! Now, I need to break this word into chunks of length 2.

1. In a Power Automate Manual trigger flow, take an Initialize variable. Provide Name, Type, and Value.

Format string Power Automate

2. In the inputs section of the Compose flow action, provide a chunk() expression that will split the string into equal chunks.

chunk(variables('Greetings'),2)
Power Automate String Expression

Output:

The output will show the below result. Refer to the image!

Microsoft Power Automate string function

Power Automate startswith

The Power Automate string function has a commonly used function known as the startswith() function. It will determine whether a provided string starts with a particular substring and return a boolean value of True or False.

It is not a case-sensitive function.

Syntax: startsWith('text', 'searchText')

Example:

Suppose I will take a sentence like ‘Welcome! Explore and enjoy your time here. I wanted to check whether the string begins with a specific substring [Hello]. Then, the output will return as false.

1. After that, take an Initialize variable flow action to store the value of a given string during the flow.

  • Name: Provide a name for the string variable.
  • Type: Select the datatype of a string from the drop-down as String.
  • Value: Take the value like “Welcome! Explore and enjoy your time here“.
Power Automate startswith

2. In the Compose flow action, take startswith() expression in it.

startsWith(variables('Greetings'),'Hello!')
startswith Power Automate

Output:

If the string starts with the search text value, then the return value will be true, else it will be false.

Power Automate string function example

The other function that resembles the Power Automate startswith() function:

FunctionDescriptionSyntax
endswith functionIt determines whether a text input string ends with a specific value or a given string.endsWith(‘text’, ‘searchText’)

Power Automate ToLower Function

In Power Automate format strings, the tolower() function converts all the characters of a string to lowercase letters.

If the string contains lowercase letters, the characters will remain unchanged, and the function will return the same lowercase characters without changing them.

Syntax: toLower('text')

Example: Assume a string as JoHAnna LoreNZ. Now, the return output will be johnna lorenz.

1. Select an Initialize variable flow action to set the variable’s value. Set the details like Name, Type, and Value.

Power Automate text string manipulation

2. Then, add a Compose flow action, and, in the Inputs property, provide the expression for the tolower expression of Power Automate, which will convert the text string to lowercase.

toLower(variables('Name'))
Lower case Power Automate example

Output:

The result will be displayed in the compose flow action. It will display the string with all the lowercase letters.

Power Automate tolower

Power Automate has one more function that resembles the tolower() function, as is mentioned in the table below:

FunctionDescriptionSyntax
toUpper() functionIt will t sets all the characters of a provided string to capital letters. For the upper case letters, it will remain unchanged.toUpper([string])

Power Automate Lastindexof

To string manipulation in Power Automate, text functions have the lastindexof() function. This function returns the starting position of the last occurrence of a string in a given string. It will also take space as an index, which will begin from 0.

Syntax: lastindexOf(['text'],'Search text ')

Example:

The lastIndexOf(‘Johanna lorenz’,’n’) function would give the output ‘12‘. In the text ‘Johanna lorenz’, this function identifies the final occurrence of the character ‘n’ index.

1. Select the initialize variable action and then set the variable name, type as a string, and the value.

Power Automate lastindexof

2. Now, select Compose action. In the Input, add the below expression:

lastIndexOf(variables('Name'),'n')
Power Automate lastindexof function

Result:

Save and test the flow manually. Then, see the result in the compose output.

  • The last occurrence of the character ‘n’ position is 12.
lastindexof Power Automate
FunctionDescriptionSyntax
IndexOf() functionIt will return the starting position or index value for a substring. The first character in the position of ‘0’ not starts with ‘1’.indexOf([‘text’],’Search text ‘)
nthIndexOf() function indexOf([‘text’],’ Search text ‘)nthIndexOf(‘text’, ‘searchText’)

Power Automate Split String

The Power Automate string expressions also have a split function: This function will split the string into substrings of an array separated by commas based on the provided delimiter.

Syntax: split('text', 'delimiter')

Example:

The code below contains the Product Details. Now, I wanted to split the strings based on the delimiter ‘|.’ The output will return an array that contains substrings.

Product Id - |WED845|
Product Type -|Keyboard|
Billing Date - |03/04/2024|
Estimated Delivery - |5|
Delivery Date - |08/04/2024|

1. Initialize a variable by providing Name, Type, and Value as shown in the below figure:

Power Automate split a string

2. After that, click on the next step, then select the compose action, and in the Inputs section, Insert the below expression:

split(variables('Product Details'),'|')
Split function in Power Automate

Output:

You can check out the screenshot below, which will split the string into an array of substrings separated with commas based on the delimiter ‘|.’

How to split a string in Power Automate

Also, you may like:

Conclusion

I trust that this Power Automate tutorial guide has information on all string functions that will be useful for manipulating text. I have covered a few examples:

  • Power Automate the length of the string
  • Power Automate concatenate strings
  • Substring Power Automate example
  • Power Automate trim string, etc.,
  • >

    Build a High-Performance Project Management Site in SharePoint Online

    User registration Power Apps canvas app

    DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

    Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

    Power Platform Tutorial FREE PDF Download

    FREE Power Platform Tutorial PDF

    Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…