Do you need to get the first character from a string in Power Automate? Then, this Power Automate tutorial will help you to get the first character from a String in Power Automate flow. We will learn:
- How to get the last character from a string in Power Automate
- How to get the last two characters from a string in Power Automate
Scenario:
While working on the product development, I needed to get the first character from the string using Power Automate flow. For example:
Input Value: United States
Once we get the first character in string value using the substring() function, The expected value looks like below:
Ouput Value: U
There is no Left() and Right () function available in Power Automate, so here I’ll explain how to get the first character in string value by using the substring() function and similarly to get the last character in string value by using the slice() function in Power Automate.
Get the first character from a String in Power Automate using substring()
Let us see how to get the first character from the string using the Power Automate flow.
substring() function
The Power Automate substring() function allows us to extract a string based on the starting index and length to extract the characters of a string.
Syntax of substring() function is:
substring (text, startIndex,length)
Example -1:
In this example, I’ll show how to extract the first character from the user input string value using flow.
Step-1:
Create an instant cloud flow with a manual trigger; add a text input for the input String as shown below:
Step-2:
Add a compose data operation and use the below expression to return the first character of a string. We can change the index value to extract the characters of a string.
substring(triggerBody()['text'],0,1)
Step-3:
Save and run the flow, Enter the input string value, and choose the run flow option. Here, I have passed the string value as EnjoySharePoint.
Once the flow runs successfully, it returns the first character of the String value as expected.
This is how to get the first character from the string using the Power Automate flow
Example-2:
In this example, I’ll show you how to get the first character of the ProductID field presented in the SharePoint list using flow.
Here, I am going to use the below Products SharePoint list, which consists of
Column Name | Column Type |
Product Name | default title column |
ProductID | Text column |
First character from ProductID | Text column |
Step-1:
Create an Automate cloud flow with a When an item is created trigger, Expand the trigger action and configure the required parameters,
- Site Address – Configure the SharePoint site address
- List Name – select the SharePoint list name (here, I have selected the Products SharePoint list)
Step-2:
Add a compose data operation, and from the dynamic content value, select the ProductID.
triggerOutputs()?['body/ProductID']
Step-3:
Add a new step, choose another compose data operation, and use the below expression to get the first character of the ProductID for the newly created list item.
substring(outputs('ProductID'),0,1)
Step-4:
Now, we will update the extracted first character from the ProductID field and update the value in the First character from the ProductID field presented in the SharePoint list.
For that, Add a new step, choose the Update item action from action triggers, and provide the below parameters:
- Site Address – select the SharePoint site address from the dropdown
- List Name – choose the SharePoint list. Here, I have selected my product list
- ID – choose the ID from dynamic content values
- Title – Pass the Title from dynamic content
In the First character from the ProductID field, use the below expression:
outputs('First_Character')
Step-5:
Save and test the flow. The flow will only trigger when a new item is created in the SharePoint list; here, I have created the below-highlighted list item.
Once the flow runs successfully, like below:
In the SharePoint list, the First character from the ProductID field gets updated with the first character of the ProductID field.
Get the last character from a String in Power Automate using slice()
Let us see how to get the last character from a string in Power Automate using the slice() function.
slice() function
The Power Automate slice() function is similar to the substring() function, which returns the string based on the starting index and ending index of a string value.
Syntax of slice() function is:
slice('<text>', <startIndex>, <endIndex>)
Example -1:
In this example, I’ll show how to extract the last character from the user input string value using flow.
Step-1:
Create an instant cloud flow with a manual trigger; add a text input for the input String as shown below:
Step-2:
Add a compose data operation and use the below expression to return the last character of a string.
slice(triggerBody()['text'],-1)
Step-3:
save and run the flow, Enter the input string value, and choose the run flow option. Here, I have passed the string value as SPGuides.
Once the flow runs successfully, it returns the last character of the String value as expected.
This is how to get the last character from the string in Power Automate.
Example-2:
In this example, I’ll show you how to get the last character of the ProductID field presented in the SharePoint list using flow.
Here, I am going to use the below Products SharePoint list, which consists of
Column Name | Column Type |
Product Name | default title column |
ProductID | Text column |
Last character from ProductID | Text column |
Step-1:
Create an Automate cloud flow with a When an item is created trigger, Expand the trigger action and configure the required parameters,
- Site Address – Configure the SharePoint site address
- List Name – select the SharePoint list name (here, I have selected the Products SharePoint list)
Step-2:
Add a compose data operation, and from the dynamic content value, select the ProductID.
triggerOutputs()?['body/ProductID']
Step-3:
Add a new step, choose another compose data operation, and use the below expression to get the last character of the ProductID for the newly created list item.
slice(outputs('ProductID'),-1)
Step-4:
Now, we will update the extracted last character from the ProductID field and update the value in the last character from the ProductID field presented in the SharePoint list.
For that, Add a new step, choose the Update item action from action triggers, and provide the below parameters:
- Site Address – select the SharePoint site address from the dropdown
- List Name – choose the SharePoint list. Here, I have selected my product list
- ID – choose the ID from dynamic content values
- Title – Pass the Title from dynamic content
In the last character from the ProductID field,
outputs('Last_Character')
Step-5:
Save and test the flow. The flow will only trigger when a new item is created in the SharePoint list; here, I have created the below-highlighted list item.
Once the flow runs successfully, like below:
In the SharePoint list, the Last character from the ProductID field gets updated with the last character of the ProductID field.
This is how to get the last character from the string in Power Automate
G the last 2 characters from a String in Power Automate
Let us see how to get the last 2 characters from the string using a flow in Power Automate.
Example -1:
In this example, I’ll show how to extract the last 2 characters from the user input string value using flow.
Step-1:
Create an instant cloud flow with a manual trigger; add a text input for the input String as shown below:
Step-2:
Add a compose data operation and use the below expression to return the last 2 characters of a string.
slice(triggerBody()['text'],-2)
Step-3:
Save and run the flow, Enter the input string value, and choose the run flow option. Here, I have passed the string value as PowerPlatform.
Once the flow runs successfully, it returns the last 2 characters of the String value as expected
This is how to get the last 2 characters from a string in Power Automate.
Example-2:
In this example, I’ll show you how to get the last 2 characters of the ProductID field presented in the SharePoint list using flow.
Here, I am going to use the below Products SharePoint list, which consists of
Column Name | Column Type |
Product Name | default title column |
ProductID | Text column |
Last 2 characters from ProductID | Text column |
Step-1:
Create an Automate cloud flow with a When an item is created trigger, Expand the trigger action and configure the required parameters,
- Site Address – Configure the SharePoint site address
- List Name – select the SharePoint list name (here, I have selected the Products SharePoint list)
Step-2:
Add a compose data operation, and from the dynamic content value, select the ProductID.
triggerOutputs()?['body/ProductID']
Step-3:
Add a new step, choose another compose data operation, and use the below expression to get the last 2 characters of the ProductID for the newly created list item.
slice(outputs('ProductID'),-2)
Step-4:
Now, we will update the extracted last 2 characters from the ProductID field and update the value in the Last character from the ProductID field presented in the SharePoint list.
For that, Add a new step, choose the Update item action from action triggers, and provide the below parameters:
- Site Address – select the SharePoint site address from the dropdown
- List Name – choose the SharePoint list. Here, I have selected my product list.
- ID – choose the ID from dynamic content values
- Title – Pass the Title from dynamic content
In the last 2 characters from the ProductID field,
outputs('Last_Character')
Step-5:
Save and test the flow. The flow will only trigger when a new item is created in the SharePoint list; here, I have created the below-highlighted list item.
Once the flow runs successfully, like below:
In the SharePoint list, the Last 2 characters from the ProductID field get updated with the Last 2 characters of ProductID.
This is how to get the last 2 characters from a string in Power Automate.
Conclusion
I hope you get an idea of how to get the first character in a string using Power Automate flow.
Additionally, I have also explained how to get the last character in a string and also how to get the last 2 characters in a string using flow.
I have shown you different examples to get the first character, last character, and last 2 characters in a string by using the substring() function and slice() function in Power Automate flow.
You may also like:
- Convert String to Float in Power Automate
- Convert a String to a Decimal Number in Power Automate
- Convert a String to an Integer in Power Automate
- How to Check Condition Contains String in Power Automate?
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.