indexOf

Summary

Gets the first 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 indexOf(string searchFor)

Returns

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

Parameters

searchFor

The substring to get the index of.

Description

Gets the first position a substring occurs at.

indexOf 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.";
Console.log(message.indexOf("quick")); // 4
Console.log(message.indexOf("fox"));   // 16
Console.log(message.indexOf("hound")); // -1

Share

HTML | BBCode | Direct Link