For a few days, I have been working on the Replace() function in Power Automate, which allows replacing characters in a string, substrings within a string, strings within an array, and strings within a JSON array, as well as multiple objects within an array.
This tutorial explains how to replace the last character of a text string using Power Automate.
Here, I will demonstrate two examples:
- Replace the Last Character of a String with Another Character
- Replace the Last ‘N’ Characters of the String with a Blank
Replace the Last Character of a String with Another Character in Power Automate
To explain this, I will take a text string, such as ‘Customer Name: CHRISTINE ANNABELLE‘, and store it in a variable. From the string, I wanted to replace the last character with another character. I.e., CHRISTINE ANNABELLA.
You can achieve this by following the steps below:
- Let’s create a Power Automate Instant cloud flow that can be triggered by a single button. If you are new to Power Automate, check out Instant cloud flow in Power Automate.
- To store the text string, add an Initialize variable. Set the name and Type as ‘String’ and enter the customer’s name as the Value.

- Then, add a ‘Compose‘ action to provide the expression that will replace the last character with another character. Insert the following expression in the Inputs parameter.
concat(substring(variables('VarCustomerName'), 0, sub(length(variables('VarCustomerName')), 1)), 'A')In the expression above, you can replace the variable with your variable.

- The flow is ready now. Save the Flow actions. Then, click on the Test icon to test the flow.
- After the flow runs successfully, you can see that the last character of a string is replaced with another character [CHRISTINE ANNABELLE -> CHRISTINE ANNABELLA]
Output:

This is how you can replace the last character from a text string using Power Automate.
Now, let’s see how to replace the last ‘n’ characters from a string in the example below.
Replace Last ‘n’ Characters with Blank in Power Automate
In this example, I will take a file name as a string from the SharePoint Document library, where the files are stored in the following format:
https://szg52.sharepoint.com/sites/HumanResourcesDepartment/InvoiceDocuments/Reports/01.jpgFrom the given string above, I want to replace the last six characters [01.jpg] with a blank, resulting in the updated Value like:
https://szg52.sharepoint.com/sites/HumanResourcesDepartment/InvoiceDocuments/ReportsTo do this, I will create a Power Automate Instant cloud flow.
Check out the steps below:
- In Power Automate, add an Instant cloud flow with a manually triggered flow trigger.
- Then, declare a variable that will store the string. For that, take an ‘Initialize variable‘ action. Provide a name for the variable, set the Type as string, and the Value with the text string value.

- After that, add a ‘Compose‘ action with the expression given below.
concat(substring(variables('VarFileURL'), 0, sub(length(variables('VarFileURL')), 6)), '')In the expression above, you can change ‘6’ with the Value representing the number of characters you want to replace.

Now, save and run the flow manually.
- You can see the result in the compose outputs, where the last ‘n’ characters have been replaced with a blank value.
Output:

This is how to replace the last characters from a string using Power Automate.
I hope you found this tutorial informative and helpful. If you have any suggestions for me, please leave your comments in the section below.
You can check out the following tutorials:
- Power Automate Replace Text in File
- Replace a File in SharePoint using Power Automate
- Replace Spaces with Underscores in String Power Automate
- Replace Double Quote with Single Quote using Power Automate

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 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 (12 times). I have also worked in companies like HP, TCS, KPIT, etc.