Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

lastIndexOf(int ch, int fromIndex) in Strings  RSS feed

 
krishna nav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lastIndexOf(int ch, int fromIndex)
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index

i didn't get this part "searching backward starting at the specified index"
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Starting from the index you pass, and going backwards.
For example : Looking for letter 'D' in the String "MYDOGISCUTE", and starting from index 6.
S -> no
I -> no
G -> no
O -> no
D -> yes, found it
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A string is a sequence of characters. You can point to any of the characters using an index. The first character of the string is at index 0. The last character is at myString.length() - 1.

You call this method on a String object, and it looks for the specified character in the string. It searches backwards, which means it starts looking from the index you specify, and goes back to the beginning, looking for the character.

Example:

[ May 31, 2006: Message edited by: Jesper Young ]
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"starting backwards from the specified index". does this make sense to you?

"abc_abd_ab"
0123456789

lastindex('b', 6) would return 5 (the 'b' in the middle), because we start at 6

cheers,
jan
 
krishna nav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.



I thank u all
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!