cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

REPLACE help

Hello,

I've been using replace with some good success lately, but just ran into a scenario that has me stumped.

Scenario:

  • Replace all "_" in filename with "/" EXCEPT in cases where filename starts with "_"
  • In those cases, Replace the leading "_" with "" (remove it)

Example:

  • replace(body('test')?['name'], '_', '/') takes "TEST_123.jpg" to "TEST/123.jpg" which is exactly what I want
  • EXCEPT when filename is "_TEST_123.jpg" I need the same output as above NOT "/TEST/123.jpg"

Ideas on how to skip the leading underscore?
Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support Team
Community Support Team

Re: REPLACE help

Hi @seadude,

 

You could create the condition to determine the File name whether is start with "_". If it is, replace the "/" to "" after filename convert. This is the introduction about substring() function, and the following code is the expression needs to be used.

replace(outputs('Compose'),'_','/')
substring(outputs('Compose_2'),1,add(length(outputs('Compose_3')),-1))

For example:

Annotation 2020-01-14 155728.png

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Super User
Super User

Re: REPLACE help

Thank you @v-litu-msft and @Gristy .

I ended up using a variation of your solution. I'm sure there is a one-liner that would accomplish this, but this will work (though it adds more complexity to an already complex Flow!)

image.png

View solution in original post

3 REPLIES 3
Super User
Super User

Re: REPLACE help

You could use substring function to always ignore the 1st character of the string?

Community Support Team
Community Support Team

Re: REPLACE help

Hi @seadude,

 

You could create the condition to determine the File name whether is start with "_". If it is, replace the "/" to "" after filename convert. This is the introduction about substring() function, and the following code is the expression needs to be used.

replace(outputs('Compose'),'_','/')
substring(outputs('Compose_2'),1,add(length(outputs('Compose_3')),-1))

For example:

Annotation 2020-01-14 155728.png

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Super User
Super User

Re: REPLACE help

Thank you @v-litu-msft and @Gristy .

I ended up using a variation of your solution. I'm sure there is a one-liner that would accomplish this, but this will work (though it adds more complexity to an already complex Flow!)

image.png

View solution in original post

Helpful resources

Announcements
firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (7,136)