Link Search Menu Expand Document

String.IndexOf Method

Explanation Finds the specified string after pos and returns the first found position.

This method finds without being aware of the character type of the target character string. Use the Find function to search for double-byte characters in the target string
Call format var n = str.IndexOf( find [, pos ] )
Return value Returns a zero -based number that indicates the location found. Returns -1 if not found
Arguments String find Character string to find
integer pos Search range start position
Specify a number starting from 0 . If omitted, the search starts from the beginning.
Exception Invalid argument
Example of use
var str1 = new String("abcdefg abcdefg");
print(str1.IndexOf("cd"), "\n");
 
 
/* When the target character string contains double-byte characters */
var str2 = new String("東京都千代田区千代田1番1号");
print(find(str2, "1", 0), "\n");
    
Related item LastIndexOfmethod
Find method