How to Replace Special Characters in a String using Power Automate

I was recently working with the Replace() function in Power Automate, which allows us to replace characters, substrings, or strings in arrays, multiple objects in JSON format, and more.

In this article, I will explain how to replace special characters from a string in Power Automate with the following examples.

  • Replace a Single Special Character from a String in Power Automate
  • Replace Multiple Special Characters in a String with Power Automate

Replace a Single Special Character from a String using Power Automate

To illustrate this example, I will manually take a text string with a special character. Below you can see the string separated with a comma:

Power Apps, Power Automate, Power BI, Power Pages

Now, I wanted to replace the comma (,) with (|) in the string mentioned above.

You can do this by using the replace() function in Power Automate.

Check out the steps below to know how to do it:

  1. On Power Automate, create an Instant cloud flow. If you are new to Power Automate, check out how to create a Power Automate Instant cloud flow.
  2. Following the trigger, add an ‘Initialize variable‘ that stores the text string with special characters. Provide a name for the variable, Type as String, and Value as a string with special characters.
Power Automate replace special characters
  1. Next, add a ‘Compose‘ action to replace the special character(,) in a string with another special character(|). Set the Inputs parameter with the below expression.
replace(variables('VarPowerPlatform'),',','|')
Power Automate replace special characters in string
  1. Now, click on the Save icon to save the flow. Then, run it manually. When the flow executes successfully, you can see the output as displayed below.

Output:

Replace special characters in string Power Automate

This is how to replace special characters in Power Automate.

Check out Power Automate Replace Text in File

Replace Multiple Special Characters in a String using Power Automate

For this example, let me take a text string that consists of multiple special characters.

The string I will use: Automate Workflows * Power Automate & analyze data | Power BI—collaborate using # Power Apps @ scale! PowerPlatform.

Here, I wanted to replace all the special characters [*,&,|,,#,@,! ] in the above string with Colon [:].

Steps to follow to achieve this:

  1. You can create a Power Automate manual trigger flow that can be triggered by a single button.
  2. To replace multiple special characters, we first need to create an array containing all the special characters. Add an Initialize variable action. Set the parameters mentioned below.
    • Name: Here, I named the variable as ‘VarSpecialCharacters‘.
    • Type: Select ‘Array‘ data type.
    • Value: Insert the expression below.
Value: createArray('.','@','ß','²','³','µ','`','´','°','^','=','(',')','&','$','§', '~','#','%','*',':','<','>','?','/','|','!',''',''','+','-','%',':','—','__','___')
Power Automate string replace special characters
  1. Next, I will declare another ‘Initialize variable‘ to store the text string containing special characters. Set the name, type, and value parameters.
Power Automate string replace multiple special characters
  1. Then, take one more ‘Initialize variable’ action that stores an empty value that is used to hold values within the Apply to each action. Provide the name, set type as string, and value as an empty value.
Replace multiple special characters Power Automate
  1. Next, add an ‘Apply to each loop’ action by taking an array of special characters in Select an output from the previous steps.
Replace multiple special characters in Power Automate
  1. Inside the loop, add a ‘Set variable‘ action to replace all the special characters with one character and declare it in an empty string variable.
    • Name: Select an empty string variable from the previous steps.
    • Value: Insert the expression below.
replace(variables('VarTextString'),item(),',')
Replace multiple special characters using Power Automate
  1. Next, take one more ‘Set variable‘ action to replace all the repeating characters. Set the parameters below:
    • Name: Here, take a text string variable with multiple special characters.
    • Value: Provide the expression placed below.
replace(variables('VarReplaceCharacters'),',',':')
Power Automate replace multiple special characters
  1. To display the output, add a ‘Compose’ action outside of the loop. In the Inputs parameter, take a [Text string variable – variables(‘VarTextString’)].
Replace multiple special characters with Power Automate

Save and execute the flow manually by clicking on the Runflow button.

Output:

Replace multiple special characters in String Power Automate

This is how you can replace special characters in a string using Power Automate.

I hope you now learn how to replace special characters in a string using Power Automate.

Found this article helpful? Leave your feedback or suggestions in the comments section!

Other Power Automate Tutorials you may like:

>

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…