How to Get the First Character from a String in Power Automate?

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:

get first character from string in power automate

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)
get first character from string in power automate flow

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.

How to get first character from string in power automate flow

Once the flow runs successfully, it returns the first character of the String value as expected.

How to get first character from string in power automate

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 NameColumn Type
Product Namedefault title column
ProductIDText column
First character from ProductIDText column
how to get the first character using Power Automate flow

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)
how to get the first character using Power Automate

Step-2:

Add a compose data operation, and from the dynamic content value, select the ProductID.

triggerOutputs()?['body/ProductID']
how to get the first character in Power Automate

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)
Get the first character in Power Automate

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')
Get the first character in Power Automate flow

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.

Get first character in Power Automate flow

Once the flow runs successfully, like below:

Get first character using flow

In the SharePoint list, the First character from the ProductID field gets updated with the first character of the ProductID field.

Get first character in Power Automate

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:

power automate get last character from string

Step-2:

Add a compose data operation and use the below expression to return the last character of a string.

slice(triggerBody()['text'],-1)
How to get first character from string using the power automate

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.

get last character from string in power automate

Once the flow runs successfully, it returns the last character of the String value as expected.

get last character from string in power automate flow

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 NameColumn Type
Product Namedefault title column
ProductIDText column
Last character from ProductIDText column
Get last character using flow

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)
Get last character in Power Automate flow

Step-2:

Add a compose data operation, and from the dynamic content value, select the ProductID.

triggerOutputs()?['body/ProductID']
Get the last character in Power Automate flow

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)
how to get the last character in Power Automate

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')
how to get the last character in Power Automate flow

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.

how to get the last character using Power Automate

Once the flow runs successfully, like below:

how to get the last character using Power Automate flow

In the SharePoint list, the Last character from the ProductID field gets updated with the last character of the ProductID field.

get last character using Power Automate flow

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:

power automate get last 2 character from string

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)
how to get last character from string in power automate

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.

get last 2 characters from string in Power Automate

Once the flow runs successfully, it returns the last 2 characters of the String value as expected

get last 2 characters from string in Power Automate flow

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 NameColumn Type
Product Namedefault title column
ProductIDText column
Last 2 characters from ProductIDText column
Get last 2 characters using flow

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)
Get the last 2 characters in Power Automate flow

Step-2:

Add a compose data operation, and from the dynamic content value, select the ProductID.

triggerOutputs()?['body/ProductID']
get the last 2 characters using Power Automate

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)
get last character using the Power Automate flow

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')
get last 2 characters from string using Power Automate flow

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.

get the last 2 characters in Power Automate

Once the flow runs successfully, like below:

how to get the last 2 characters in Power Automate flow

In the SharePoint list, the Last 2 characters from the ProductID field get updated with the Last 2 characters of ProductID.

how to get the last 2 characters in Power Automate

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:

>