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

Notifications

Announcements

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,195 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard