cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MaryT0905
Resolver I
Resolver I

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
Resolver I
Resolver I

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
Super User
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
Resolver I
Resolver I

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
Resolver I
Resolver I

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
Super User
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
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

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.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,026)