cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
seadude
Memorable Member
Memorable Member

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
v-litu-msft
Community Support
Community Support

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

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
Gristy
Resident Rockstar
Resident Rockstar

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

v-litu-msft
Community Support
Community Support

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

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Users online (3,122)