web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Using substring and in...
Power Automate
Answered

Using substring and indexOf to get middle of string between two indexes, but having trouble

(0) ShareShare
ReportReport
Posted on by 4

I've got a flow set up to send a bot message to Teams when a file is changed in a shared OneDrive directory. The message includes a link to the folder where the file resides. I want the text of this link to be the path of the directory, but in order for it to be user friendly, I want to only keep the part of the path which is after 'root:' and before the file name.

I want to do something like this:

substring( File Path, indexOf( File Path, 'root:' ) + 5, indexOf( File Path, File Name ) - indexOf( File Path, 'root:' ) + 5 )

 

To take this: 

"/drives/b!KosGUJrQ10-JHf8xWUb2Zvba5vzW4a2Du7qcWPXQ99r1usopxzphRrN1IXAVuIeF/root:/External Shared/10466_SAFB/Exports/SAFB_PP.nwc"

to this: 

"/External Shared/10466_SAFB/Exports/"

 

From what I can tell, Power Fx doesn't like the math operators in my expression. The expression returns no errors without the operators, but without the operators, I can't get the specific mid section of the string I want.

 

Any work arounds or suggestions?

Categories:
I have the same question (0)
  • Verified answer
    Expiscornovus Profile Picture
    33,844 Most Valuable Professional on at

    Hi @j_f,

     

    If you want to add 5 characters you could use the add function instead of the +

     

    Try something like:

    add(indexOf( File Path, 'root:' ), 5)

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Hopefully this will get what you're looking for. Assuming the Path is in a Compose action.

     

    slice(outputs('Compose'), add(indexOf(outputs('Compose'), 'root:'), 5), add(lastIndexOf(outputs('Compose'), '/'), 1))

     

    grantjenkins_0-1681309409335.png

     

    grantjenkins_1-1681309450640.png

  • j_f Profile Picture
    4 on at

    Thanks! I'm happy there are people out there who know more than me! I got the result I wanted using a combination of add() and sub() within the substring() function and Dynamic input for the path.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 594

#2
Valantis Profile Picture

Valantis 469

#3
11manish Profile Picture

11manish 364

Last 30 days Overall leaderboard