Power Automate String functions allow users to convert strings, string characters, format strings, and more. They are used extensively to convert data to other sources. In this tutorial, we’ll go through some complicated String functions that can be used in Microsoft flows – the substring and indexOf functions.
Power Automate String Function: Substring
First, let’s discuss the substring function. This is used if we want the user to input their first name and last name, and we only want to return the first name or last name.
The substring function returns characters from a string starting on the specified position.
Let’s try that out in this sample flow that I previously created. We’ll remove this current content that I’ve set for the Message text.
Under the String functions selection, choose the substring function. This contains the text, startIndex, and length parameters.
Once clicked, go to the Dynamic content tab then choose Input 1.
Let’s set the startIndex to 0 since we want it to start at 0. Then it should display 5 letters.
To summarize, this function will take whatever Input 1 is. Then it’ll only give us the characters from the text between zero and five. Let’s now click OK.
Let’s combine that with the concatenation as well. So, click the Concat function.
Cut (Ctrl + X) the whole substring function.
Then paste it inside the concat function.
For the first argument, let’s type “The user first name is”.
Then, click Update.
Lastly, click Save.
Testing The Substring Function
Let’s now test the flow.
We’ll just use the data from my previous runs.
My input during my previous runs was Henry. That’s why it displayed “The user first name is: Henry”.
Therefore, the substring function worked like it was supposed to. Let’s try to test the flow again and enter a new input. Let’s type in Shelley for Input 1 and run the flow.
As we can see, it just displayed “shell” instead of “Shelley”. That’s because we specified that it should only display 5 characters. And that’s how the substring function works.
Power Automate String Function: IndexOf
Let’s now discuss what the power automate indexOf function does.
The indexOf function finds the index or position of a character within a given string in a case insensitive way.
This power automate string function requires two parameters: the string that contains the value and the value to search the index of. Now let’s go back to our flow and let’s add a new Text input.
For this input, we want the user to enter their email.
We want to return only the characters before the @ character and not the whole email. To do that, let’s first remove the initial expression that we created.
We need to combine the substring with the indexOf function. Under the Expressions tab, choose the substring function.
Then, choose Input 3 under the Dynamic content tab.
For the startIndex parameter, let’s set 0. The length should be the index of the @ character. Click the indexOf function.
Choose Input 3 under the Dynamic content tab.
Then let’s specify the character that we want to find within the text. In this case, it’s the “@” sign. Then click OK.
Testing The Flow
Let’s now save and test the flow.
Let’s perform a new trigger action then click Save & Test.
Just type in anything for the other inputs. As for Input 3, let’s type “email@example.com”. Then click Run flow.
When we check our Slack, we’ll see that it posted the word “nicholas”. By combining those two functions, the flow will always return the characters before the @ sign. This makes our expression more dynamic.
***** Related Links *****
Microsoft Flow String Functions: Concat And Replace
Power Automate Documentation Walkthrough
Power Automate Terminate Action Control In Flows
In this post, we discussed the common use cases for string functions. We can also use certain string functions along with the others such as combining the substring and indexOf functions. We do this to get more specific characters within the text especially if the length of the string changes. Making our expressions for these kinds of instances is certainly useful and efficient.
There are many other Power Automate string functions that you can use for your flows. We’ll be discussing some of them in our other blogs. Hopefully, you were able to grasp the usage and importance of these two string functions.
All the best,