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. public int indexOf(string searchFor) public int indexOf(string searchFor, int startingIndex) public int indexOf(System.RegExp searchFor) public int indexOf(System.RegExp searchFor, int startingIndex) Usage public int indexOf(string searchFor) public int indexOf(string searchFor, int startingIndex) public int indexOf(System.RegExp searchFor) public int indexOf(System.RegExp searchFor, int startingIndex) Returns The position of the first occurrence of the substring. -1 if the substring was not found. The position of the first occurrence of the substring. -1 if the substring was not found. The first position the regular expression matches at. -1 if the regular expression failed to match anything. The first position the regular expression matches at. -1 if the regular expression failed to match anything. Parameters searchFor The substring to get the index of. Parameters searchFor The substring to get the index of. startingIndex The index to begin searching for the substring from. Parameters searchFor The regular expression to match. Parameters searchFor The regular expression to match. startingIndex The index to begin matching the regular expression from. Description Gets the first position a substring occurs at. indexOf will return -1 if the substring could not be found. Gets the first position a substring occurs at, beginning from a certain starting index. indexOf will return -1 if the substring could not be found. Gets the first position a regular expression matches at. Alias for JavaScript's String.prototype.search(). JavaScript's String.prototype.search() is not implemented in JS++ because it's just indexOf that takes a regular expression. Thus, to prevent confusion, indexOf was overloaded to take a regular expression argument. indexOf will return -1 if the regular expression could not match. Gets the first position a regular expression matches at, beginning from a certain starting index. indexOf will return -1 if the regular expression could not match. Examples Basic Usage 123456import System; string message = "The quick brown fox.";Console.log(message.indexOf("quick")); // 4Console.log(message.indexOf("fox")); // 16Console.log(message.indexOf("hound")); // -1 Basic Usage 12345import System; string message = "The quick brown fox.";Console.log(message.indexOf("quick", 10)); // -1Console.log(message.indexOf("fox", 10)); // 16 Basic Usage 123456import System; string message = "The quick brown fox.";Console.log(message.indexOf(/QUICK/i)); // 4Console.log(message.indexOf(/fox\./)); // 16Console.log(message.indexOf(/aaa/)); // -1 Basic Usage 123456import System; string message = "The quick brown fox.";Console.log(message.indexOf(/QUICK/i, 10)); // -1Console.log(message.indexOf(/fox\./, 10)); // 16Console.log(message.indexOf(/aaa/, 10)); // -1 Share HTML | BBCode | Direct Link