What is LastIndexOf method and how it works?

Hello There,

Can someone please explain with a simple example of the “LastIndexOf” method? I somehow can’t see to understand this one …

Thanks in Advance

Hi @Hara_Gopal,

I assume this for string method:

" LastIndexOf () method is used to find index position of the last occurrence of a specified character or string within String.".

Please refer the below post:

Sasikumar K

if the input string is “You searched for author Mark Twain. His books can be found in the following stores: Bookland,Classics bookstore.” and you want to get only the author i.e.“Mark Twain”,

You would be using one the expressions like,

First part is,it splits by period symbol(.) then it takes only the FIRST part,then it find the substring in that part from the last till reached the word “author” as we mentioned there as a parameter.


hi @Hara_Gopal
“LastIndexof” will give you last occurrence of that string.
Example:- message=“aliabhatt”

so message.LastIndexof(“a”) will give —>6(bcoz last occurrence of “a” is at 6)

and message.indexof(“a”) will give—>0(first occurrence)


thank you so much

1 Like

thank you so much !