Power Automate replace all special characters

Loading

Requirement: how to replace all special characters from the string in Power Automate.

Create “Manually trigger a flow” and add an action “initialize variable” and then give a variable name, type as an array, and in value write the below expression:

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

Now variables contain all special characters, later use  Apply to each. And also this variable gets updated with the special characters, that is to replace with another character or value.

Now in variable assign a sample string contains a special character, so click on the Next step. Then select Initialize variable action and provide the variable name, type as string, and set the value like below:

Now initialize two variables to hold the values later in apply to each action.

Next, click on the next step and select Apply to each action in the output set the variable ‘special characters’.

Now replace the special character in the string with an underscore, so click on the Add an action then select Set variable action, then select the variable name ‘replace special character’, and in values write the below expression:

replace(variables('Stringwithspecialcharaters'),item(),'_')

Remove the repeating character, so click on the Next step and select Set variable action, and then provide the variable name and write the below expression:

replace(variables('replacespecialcharacter'),item(),'_')

Next click on the next step, and select set variable action, then provide the variable name and in value select the ‘replacerepeatcharacter’ from the dynamic content.

To see the result use the compose action, so click on Next step and in input select the variable ‘stringwithspecialcharacter’.

Now click on Save and run the flow manually, can see the result in the compose action.

Leave a Reply

Your email address will not be published. Required fields are marked *