cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
benny_blanco
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
bibhupanigrahi
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
Paulie78
Super User III
Super User III

OK Benny Blanco from the Bronx!!

GetTheValue.PNG

Expression:

 

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

 

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

 

bibhupanigrahi
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

Paulie78
Super User III
Super User III

Wow - I read the question completely wrong. 😄

Paulie78
Super User III
Super User III

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

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

BennyBlanco.PNG

benny_blanco
Helper I
Helper I

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

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.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,792)