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

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

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 Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard