cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JoshPayneSays
Frequent Visitor

Replace multiple spaces with single underscore

I would like build a Flow which replaces any number of spaces within a string with x1 underscore ('_').

 

Note! Just for demonstration purposes I will denote the space with a #. In my real world example the character I wish to replace is a simple space (i.e.' ').

 

There can be any number of spaces with the source string (i.e. x1 or x2 or x3 or x4..... xN).

 

E.g.

 

Source String: "StartName#OneSpace####FourSpace##TwoSpace###ThreeSpace"

Result I would like: "StartName_OneSpace_FourSpace_TwoSpace_ThreeSpace"

 

Thank you in advance

ScrSht_err_PwrFlw_replaceSpaceHelp_01.png

3 REPLIES 3
ChrisPiasecki
Super User
Super User

Hi @JoshPayneSays,

 

You can first use the Split function, using space as the delimiter.

Second, you can then use the Filter Array action such that it only includes items where the expression empty is false. This excludes all array items with a space. 

 

Finally, you can use the join expression, using underscore as the character to join the remaining words together.

 

Refer to the article below for an example of how to do this, the only difference is you are joining with an underscore instead of a space in the last step.

 

https://debajmecrm.com/how-to-remove-trailing-spaces-and-extra-spaces-in-a-string-in-power-automate/

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

Hi @ChrisPiasecki , I shall have a look and revert asap. Cheers in advance.

ChrisPiasecki
Super User
Super User

Hi @JoshPayneSays,

 

Just following up on whether the above steps worked for you?

 

---
Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

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

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors
Users online (1,116)