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?
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?
This was very useful but please note the last line should read :
Find(_lookingFor & Last(Split(_aString, _lookingFor)).Value, _aString)
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.
WarrenBelz
78
Most Valuable Professional
MS.Ragavendar
49
mmbr1606
41
Super User 2025 Season 1