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

Getting substring out of a string in PowerAutomate using an expression

Hi all,

 

I'm building this Flow that needs to rename a created document before it gets moved to a folder. Couldn't find what I'm looking for in here, so posting a new topic for it. I'm trying to get everything after the second '-' character in a string. For example, out of the string 'BugsBunny-Arn-999999-67378-CLMPDVVD-TB-GN.docx', I'm trying to make it to be only '999999-67378-CLMPDVVD-TB-GN.docx', what is the correct expression that will work? Have in mind that'd be a dynamic value, so I'm basically taking the Name of the file first and then need to convert it to have only what is after the second '-' character. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Resolver III
Resolver III

Hi @benny_blanco , you cannot easily find second index of a character in a string, so the substring() function is not helpful here. I used a combination of split() and join() to get the exact part of string in this case.

1. Split the original string using the expression "split(variables('mystring'),'-')". This creates an array.
2. Now join the array elements in a a Compose starting the third item in the array using the expression "join(skip(variables('myarray'),2), '-')". This results in the string you want.

get-substring-with-split-and-join1.jpgget-substring-with-split-and-join2.jpg

Hope this helps!

View solution in original post

5 REPLIES 5
Resident Rockstar
Resident Rockstar

OK Benny Blanco from the Bronx!!

GetTheValue.PNG

Expression:

 

split(outputs('Compose'), '-')[2]

 

https://www.youtube.com/watch?v=zMA5uCYloDk

 

Resolver III
Resolver III

Hi @benny_blanco , you cannot easily find second index of a character in a string, so the substring() function is not helpful here. I used a combination of split() and join() to get the exact part of string in this case.

1. Split the original string using the expression "split(variables('mystring'),'-')". This creates an array.
2. Now join the array elements in a a Compose starting the third item in the array using the expression "join(skip(variables('myarray'),2), '-')". This results in the string you want.

get-substring-with-split-and-join1.jpgget-substring-with-split-and-join2.jpg

Hope this helps!

View solution in original post

Resident Rockstar
Resident Rockstar

Wow - I read the question completely wrong. 😄

Resident Rockstar
Resident Rockstar

This is my new version now I have read the question properly:

join(skip(split(outputs('Compose'), '-'),2),'-')

BennyBlanco.PNG

Helper I
Helper I

Just tested bibhupanigrahi's suggestion which worked perfectly. Thank you @bibhupanigrahi !

Helpful resources

Announcements
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (6,579)