What is the lastIndexOf method?

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

What is the lastIndexOf method?

Rating:

The lastIndexOf method belongs to the string object. This method searches a string for a character or a group of characters from the last character of the string and returns its index. The index values for each character are counted from the first character. The position of the first character in the string is considered to be at index 0. The method returns -1 when the character is not found.

The syntax of the lastIndexOf method is as follows:

lastIndexOf(value:String, [startIndex:Number])

The parameter value is the character or a group of characters to search for.

The parameter startIndex is optional. If this parameter is provided, the counting is started from the character whose index value is one more than the value of the startindex. For example, if the startindex is 3, the search will start from the 4th character.

Some examples of using the lastIndexOf method are as follows:

trace("This is a string".lastIndexOf("g")) //output: 15
trace("This is a string".lastIndexOf("s",5)) //output: 3
trace("This is a string".lastIndexOf("str")) //output: 10
trace("This is a string".lastIndexOf("z")) //output: -1


Rating:



Other articles

Click here to Article home

MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.
 
HACKER SAFE certified sites prevent over 99.9% of hacker crime.