This post explains how to remove unwanted characters from a string in a Power Automate flow. These can be regular characters or unprintable special characters, such as control codes that you need to strip out.
The example string:
<note> <to>[email protected]</to> <from>Michael Knight</from> <heading>Reminder</heading> <body>Don't forget to clean KITT this weekend!!! </body> </note>
I want to remove the apostrophe, exclamation marks and non-printable characters.
You can see the non-printable characters in Notepad++ :
First of all, let’s take a look at the basic flow structure:
In the above example I have only put two characters in the array, like this:
[ "\u0027", "!" ]
This requires some explanation, you might be wondering what the first element in the array is!
\u0027 is the Unicode representation of the apostrophe character. The complete array to remove everything I want to clean from this string is:
[ "\u0001", "\u0007", "\u0027", "!" ]
It’s important to know how to remove non-printable characters or control codes, because you cannot type them into the expression editor in Power Automate. So using the Unicode representation makes it possible.
A note of caution, if you load up a big array of unwanted characters like this:
[ "\u0001", "\u0007", "'", "!", "@", "£", "^", "=", ",", "%", "[", "]", ";", "~", "?", "<", ">", "|", "`", "¬", "/" ]
Then the apply to each loop will take longer to execute. So try to keep the number of replacements down to the minimum possible. If you want more speed you can do it all in a single action with a nested replace, but it is more difficult to read.
Hope this helps.