lastIndexOf

Summary

Gets the last position a substring occurs at or regular expression matches at.

Signatures

Click on a signature to select it and view its documentation.

Usage

public int lastIndexOf(string searchFor)

Returns

The position of the last occurrence of the substring. -1 if the substring was not found.

Parameters

searchFor

The substring to get the last index of.

Description

Gets the last position a substring occurs at.

lastIndexOf will return -1 if the substring could not be found.

Examples

Basic Usage
1
2
3
4
5
6
import System;
 
string message = "The quick brown fox jumped again and again.";
Console.log(message.indexOf("again"));       // 27, first index of "again"
Console.log(message.lastIndexOf("again"));   // 37, last index of "again"
Console.log(message.lastIndexOf("hound"));   // -1, substring could not be found

Share

HTML | BBCode | Direct Link