How to Replace Apostrophe in String in Power Automate?

I was recently working on string manipulations in Power Automate, where we wanted to replace apostrophes with double quotes. You can do it easily.

In this tutorial, I will show you how to replace an apostrophe character in a string in Power Automate. Additionally, I will cover the following examples.

  • Replace the apostrophe mark in a Power Automate string variable
  • Replace the apostrophe with a blank value using Power Automate
  • Replace a single apostrophe with a double apostrophe in Power Automate

Replace Apostrophe in String Variable in Power Automate

Suppose you have a string variable that stores a country value within apostrophes that can be used during the flow execution. Example: ‘United States of America’

Now, you want to replace it with double quotes, like “United States of America”.

You can do this by using the steps below in Power Automate.

  1. Create an Instant cloud flow in Power Automate that can be triggered manually by clicking a button.
  2. To store the string value, add an “Initialize variable” action and set the parameters, such as Name, Type, and Value.
Power Automate replace apostrophe in string
  1. Next, add a “Compose” action to replace the apostrophe present in a string variable. Provide the below expression in the Inputs section.
replace(variables('VarCountryName'),'''','"')
Replace apostrophe in string Power Automate
  1. Now, the flow is ready to save and test. Click on the Save button -> then the Test icon. In the Test flow pane, select Manually and click on Test.
Replace apostrophe from string Power Automate
  1. Once the flow runs successfully, you can see that the apostrophe present in a string variable is replaced with double quotes.
Replace apostrophe in string variable Power Automate

Now, let’s have a look at another example that will replace the apostrophe with the blank value using Power Automate.

Check out How to Update SharePoint List Items from Excel using Power Automate?

Replace Apostrophe with Blank using Power Automate

Suppose I consider a URL of a SharePoint document library file, i.e., with an apostrophe symbol, like the one below. But that is not correct. Now, I wanted to replace the apostrophe with a blank value to browse it correctly.

'https://your tenant.sharepoint.com/sites/HR/HRDocuments/Policy.docx

Here, I will also create a Power Automate Instant cloud flow.

See the steps below:

  1. To the Power Automate flow canvas, add a “Compose” action to store the URL of a SharePoint document library file.
Microsoft Power Automate replace apostrophe
  1. Now, add another “Compose” action to replace the apostrophe with a blank value. Insert the code below in the Inputs parameter.
replace(outputs('Compose_-_Policy_Document'),'''','')
Replace String Apostrophe with blank Power Automate

Save and test the flow manually.

Output:

Replace apostrophe String Power Automate

This way, you can replace an apostrophe with a blank value in Power Automate.

Replace Single Apostrophe with Double Apostrophe in Power Automate

This is an interesting example, and I’m sure you’ll love it.

Many times, you may need to replace a single apostrophe with a double apostrophe in Power Automate.

Here is an example.

As you can see, below is a Project Information List, where each project has different clients. To filter SharePoint list items by client name in Power Automate, we can use the filter query in the Get Items action.

However, the filter query will work correctly for all items, except for the list items that contain a client name with an apostrophe mark (In this case, it is D’Souza).

Power Automate Replace Apostrophe from a String

The filter query will return an error if the client’s name has an Apostrophe mark [Single quotation mark].

ProjectClient eq 'D'Souza' - Returns error

The reason for the error is that the query searches for the text within the single quotes. So the search actually would be looking for ‘D’ and then it doesn’t know what to do with the 2nd part of the string ‘Souza’, so it fails.

Power automate replace with apostrophe

To avoid this error, we need to replace the apostrophe with a double apostrophe, so that it will not generate the error.

Follow the steps below:

  1. Create a Power Automate Instant cloud flow.
  2. After that, add an ‘Initialize variable‘ flow action. Here, I will use the value as the client’s name that I want to filter inside the filter query.
Replace Single Quotes in Power Automate
  1. Then, add a ‘Get items‘ action that will filter the SharePoint list items based on the client’s name. Provide the Site Address and List Name.
    • Filter Query: Insert the expression below.
ProjectClient eq '@{replace(variables('Client Name'),'''','''''')}'

Note:

To replace the single quote (Apostrophe ) in a string, you need to use two single quotes in the replace expression. Here, we are replacing with 2 single quotes, then we need to place 4 single quotes inside the replace() expression wrapped with another two single quotes. Then, total it will be 6.

Power Automate replace single quotes in a String
  1. Now, save and run the flow. The flow doesn’t generate any error, and it will fetch the item that matches the filter query.
How to replace apostrophe in string Power Automate

This is how to replace a single apostrophe with a double apostrophe in Power Automate.

I hope you now understand how to replace an apostrophe in a string using Power Automate with various examples.

I hope this article was helpful. If you have any thoughts or suggestions, mention them in the comment section.

You may like the following tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…