What is the lastIndexOf method?

December 30th, 2007 by uCertify Leave a reply »

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

Best exam simulation Adobe ace-flash download free trial. Click here to download 9A0-311 test study guide and practice question.
  • Share/Bookmark
Advertisement

Leave a Reply

uCertify.com | Our Company | Articles | Contact Us | News and Press Release | uCertify India | Entries (RSS)
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD    Cisco Certification: CCNA, CCENT    A+, Network+, Security+ Project+
Oracle Certification: OCP 11g, OCP 10g, OCA 11g, OCA 10g    CIW foundation    EC-212-32,    CISSP    Photoshop ACE CS4    Adobe Flash ACE, PMP, CAPM
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.