Power Automate slice() Function

Are you eagerly waiting to learn how the Power Automate Slice() function works? Then, read this complete tutorial, where I will explain the Power Automate slice() function, its syntax, and an example based on the slice() function in Power Automate.

Power Automate slice() function is used to extract a piece of text or a part of a string from the provided text in a flow. The Power Automate slice() function is an enhanced version of the substring() function that cuts the string based on the start and end indexes. Example: slice(triggerBody()[‘text’],0,4).

slice() Function in Power Automate

The Power Automate slice() function extracts part of a text string or a substring from a given string by giving a string’s starting and ending position.

The slice() function is similar to the Power Automate substring() function, where both functions return the contents of a string, but the substring() function differs in parameters like the start index and the length of the Substring.

In the Power Automate slice() expression, we can also pass the negative values in the startIndex parameter, which will take the count of index position from the backward, i.e., end of the string.

Example:[slice(‘Lidia Holloway’, -6)] => Return “lloway.”

Syntax of slice() Function in Power Automate

The syntax for a Power Automate slice() function looks like this:

slice('[text]', [startIndex], [endIndex])

Example of Power Automate slice() expression: slice(‘Joni Sherman’, 0,4) => It will return “Joni”.

Parameters:

  • Text: It is a mandatory field that has a substring to be identified in it.
  • Start Index: This should be given as an integer that includes the starting position of a text from where the substring should be extracted. For example, the start index for’ Power Automate -> ‘P’ is ‘0’. Similarly, the start index for’ o’ is ‘1’, and for ‘A’ it is ‘6’.
  • End Index: It is also in the form of an integer that includes the end position of a searching substring. The end index is optional. If the end index is not given in the slice() expression, it will return a string from the startIndex position to the endIndex position.
    • Example: slice(‘Lidia Holloway’, 3) => Return the string like ” ia Holloway”.
Note: First character on the position of '0'

It returns the value in the form of a substring that is identified in between the two numbers of the start index and the end index.

Power Automate slice() Function Examples

Here, I will explain examples of how to use the slice() function in Power Automate to extract a part of a string.

Follow the below-mentioned steps to create a Power Automate flow.

Example:-1

1. Navigate to make.powerautomate.com in the browser to open the Power Automate Home page -> Tap on +Create -> Select ‘Instant cloud flow’ -> In the next window, select a trigger ‘Manually trigger a flow’ and enter a flow name -> Click Create.

  • Open the trigger -> Click Add an input -> Select Text.
How to use the slice() function in Power Automate

2. To give the slice() expression in a flow, add an ‘Initialize variable’ flow action under the flow trigger. The Initialize variable stores the information, and the stored values can be used during the flow.

  • In the initialized variable, give Name, Type, and Value.
Value: slice(triggerBody()['text'],0,4)
Power Automate slice() function

3. To view the output of the Power Automate slice() function, we can use the ‘Compose’ data operation. Add the ‘Compose’ data operation and give the value in the ‘Inputs’ section.

slice() string function Power Automate

4. Now, the flow is ready to Save and Test. Click on Save. Test the flow Manually. In the Run flow window, Provide the text value -> Click on Runflow.

Power Automate slice() expressions

5. When the flow runs successfully, it will notify a message as ‘Your flow ran successfully.’ Then, open the ‘compose’ flow action to see the output. The output will be received as a substring from the given string between the indexes.

Power Automate cut string with slice() Function

This is how to extract text from a string from Power Automate’s slice() expression.

Example:-2

Let me explain one more Power Automate’s slice() string example to get a string between two characters.

I will do this by using a SharePoint list. The SharePoint list has a few columns, like Full Name and DOB. In this SharePoint list, we wanted to cut the string between two characters of ”Full Name” according to the requirement.

The screenshot shows the image of the SharePoint list:

Power Automate slice expression example

Similarly, follow the steps mentioned in the above example to create a flow.

I will create an “Automated cloud flow” in Power Automate that will trigger automatically.

1. Log in to the Power Automate with Microsoft credentials. On the Power Automate Home page, tap +Create -> Select “Automated cloud flow” -> Enter Flow name, and select trigger. In the trigger, choose Site Address and List Name.

slice() function in Power Automate

2. In a flow, add a flow action, i.e., ‘Initialize variable.’ Initializing a variable at the beginning of your flow can be used to modify, set, and retrieve its value as needed. Then, set the parameters as below:

Power Automate slice() expression example

3. Take a “Compose” data operation to check the value returned from the Power Automate slice() expression. In the “Inputs,” add the below value as given in the code.

slice(variables('Name'),0,6)
Power Automate string functions slice() function

4. Now, make sure to Save the flow. Then, Test the flow Manually. After that, create a new item in the SharePoint list to see the flow work.

5. The below image shows the output of a slice() function, which extracts text between two words in Power Automate flow based on the SharePoint list column ‘Full Name.’

Use slice() expression in Power Automate

This is how to use the Power Automate string slice() function to cut the text between the characters.

Conclusion

I trust this Power Automate tutorial taught in detail information about the Power Automate Slice() Function. Below are the topics that I have covered in this tutorial.

  • Power Automate slice() function
  • Power Automate slice() function syntax
  • Power Automate slice() function examples

You may like the following tutorials: