cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MaryT0905
Helper III
Helper III

Using an Expression to Create an Array for certain characters

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
MaryT0905
Helper III
Helper III

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

MaryT0905_0-1642635241020.pngMaryT0905_1-1642635247315.png

 

MaryT0905_2-1642635256222.png

 

 

View solution in original post

4 REPLIES 4
Expiscornovus
Dual Super User
Dual Super User

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'])

 

MaryT0905
Helper III
Helper III

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

MaryT0905_0-1642624109403.png

 

MaryT0905
Helper III
Helper III

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

MaryT0905_0-1642635241020.pngMaryT0905_1-1642635247315.png

 

MaryT0905_2-1642635256222.png

 

 

Expiscornovus
Dual Super User
Dual Super User

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.

 

sanitise_chars.png

 

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

New Process Advisor Capabilities carousel.png

Read the blog for the latest news

Read the latest about new experiences and capabilities in the Power Automate product blog.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (3,060)