Flow: Stripping Unwanted Characters or Special Characters From a String

Hi All.

For those who may need a way to strip special characters from a string then here is a method using Microsoft Flow. You will create an array of special characters then iterate through your string data replacing any of the matching characters then outputting the sanitised string at the end. Whilst I am using a compose called "Compose Email Subject", this could be any string when you decide to incorporate this into your Flow.

So, we will take this: https://emea.flow.microsoft.com/manage/environments/

And make it this: httpsemeaflowmicrosoftcommanageenvironments

Here is the Flow.

The trigger I have used is a button, although this could just as well be any trigger. Once the concept has been grasped here it is likely that this will be built into your own existing Flow. It just helps using a button to test so maybe start by building like for like in order to grasp the concept before incorporating into your own process.

Now a "Compose" called "Compose Email Subject". This is used for you to test your own email subject or string of your choosing so you can determine if the sanitation is complete in your case. Please change the value to suit.

https://emea.flow.microsoft.com/manage/environments/

Now let's initialise 3 variables as below:

createArray('.','@','ß','²','³','µ','`','´','°','^','=','(',')','&','$','§', '~','#','%','*',':','<','>','?','/','|',' ')

The above can be changed to suit. For example, if you only want to strip out a colon and a slash you could have.

createArray(':','/')

To follow best practice, create your own "Apply to each" and name it "Apply To Each InvalidCharacters", or a name of your choosing and within set 2 variables.

replace(variables('Sanitise'), item(), ")

To finish off, outwith the looping control (Apply to each) add a compose called "Compose Sanitised Subject", as below.

I hope this is helpful to you.

Any issues or questions, please reference this blog and post in Get Help with Microsoft Flow.

Happy Flowing!

Thanks, Alan