I need to remove commas, single quotes, and apostrophes for an address line for an integration I am working on. The other system doesn't like these, and sometimes the user puts these in by mistake on web orders.
Following this article
I know I need to use an expression to create an array so I can then filter them out.
Using this article
I I know I can use Replace, to account for the single quotes and apostrophes, but I'm not really sure how to string that together because I'm not sure what I should put in for the value part of replace(<value>,.....
Can someone please help me understand how to put this together 🙂
THank you!
Solved! Go to Solution.
I read this article Power Automate: replace Function - Manuel T. Gomes (manueltgomes.com)
And decided against nesting the replace function
Instead I did a replace value on the first input, passed that through to the next step, and did another replace value. Thereby cleaning it along the way
Hi @MaryT0905,
Following the article from Alan you could use the following type of values as an InvalidCharacters array.
[{"character":"â", "replacement":"a"}, {"character":"é", "replacement":"e"}]
In the loop in the Set Variable Alias action you could use an expression like this:
replace(variables('Sanitise'), item()['character'], item()['replacement'])
I'm still struggling here. I can't create an array for single quotes or apostrophes. I can use the replace option, but only for one character. I can't figure out how to get mulitple characters to include
Replace(outputs('Compose'),',' , ' ' ', ' '' ', ' ') This is what I want but I get the following error message
I read this article Power Automate: replace Function - Manuel T. Gomes (manueltgomes.com)
And decided against nesting the replace function
Instead I did a replace value on the first input, passed that through to the next step, and did another replace value. Thereby cleaning it along the way
Hi @MaryT0905,
Great that you found another solution which works for you 😀
Apologies if I wasn't really clear on my proposed approach. For future reference a bit more explanation what I was suggesting.
The code snippet below could have been the array for cleaning up the string in apply to each loop, like described in Alan his post from your opening post.
[
{
"character": ",",
"replacement": ""
},
{
"character": "’",
"replacement": ""
},
{
"character": "'",
"replacement": ""
}
]
Instead of having separate actions for each character you would have a single action which looks at whatever value is in the character field and replaces it by whatever is in the replacement field, per array item. The array above contains three items, so the apply to each loop will try and replace 3 characters.
The replace function below could have replaced (pun intended) the expression in the Set Variable Alias action of Alan his approach.
As you can see that it just refers to an item (of the InvalidCharacters array) and the character and replacement columns:
replace(variables('Sanitise'), item()['character'], item()['replacement'])
Benefit of this approach is that you don't need to add more actions when you have more characters for cleaning up. You only need to add the character and it's replacement value as an item to the existing InvalidCharacters array variable.