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 Apps / lastindexOf() or a Fin...
Power Apps
Unanswered

lastindexOf() or a Find() from the right of a string

(0) ShareShare
ReportReport
Posted on by 3,340

I need to find the index of the last instance of a character in a string.  In the Flow expression builder, there is the lastindexOf() statement.  I need a suitable way to do this in PA.  We have one?

Categories:
I have the same question (0)
  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @martinav 

    There is no particular LastIndexOf in PowerApps.

     

    But consider the following formula:

    With({_aString: "This is, may I say, quite and interesting way to go, or get past, or complete",
     _lookingFor: ","},
     If(EndsWith(_aString, _lookingFor), 
     Len(_aString),
     Find(_lookingFor & Last(Split(_aString, _lookingFor)).Result, _aString)
     )
    )

    This will return 65 - which is the last index of the ","

    If the "," in this case is at the end, it will provide the ending location.

     

    I hope this is helpful for you.

  • DThompsòn Profile Picture
    5 on at

    This was very useful but please note the last line should read : 

     

     

    Find(_lookingFor & Last(Split(_aString, _lookingFor)).Value, _aString)

     

  • JenniferK Profile Picture
    167 on at

    I was so happy to find this solution! It's clear and succinct. I did however, find a corner case where it fails. Consider the following:

    mystring= "A charge is levied for any instrument or radioactive source that is found to be unsuitable for calibration. The fee covers inspection and return, and is based on the work done prior to the discovery of the fault."
    
    With(
     {_lookingFor: " "}, 
     Find(_lookingFor & Last(Split(mystring, _lookingFor)).Value, mystring) //returns 38, which is the position of the first occurence of the letter o because Find is looking for "o ".
    )

    My usual approach to finding the last _lookingFor in a string is to reverse the string and find the first position of the _lookingFor and then subtract it from the string length and do Left(mystring, someposition). But PowerApps (at least in canvas) doesn't seem to have an easy way to reverse a string.

     

    Do you have any suggestions to deal with the cornercase I've illustrated?

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 Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard