Main Index : Reference :
[int] strstr([string] str,[string] phrase)[int] strstr([string] str,[string] phrase,[int] pos)
str is the string.phrase is the search phrase.pos is the optional start position of the search.
strstr() returns the position of the first occurence of the string phrase within the string str. If the third parameter is passed, only the part of str that is after the position pos is searched. If no match is found, the return value is -1.
Remember: The first character of a string is at position 0.
// Outputs "2". The phrase is located at position 2.
var str = "abcdefghij";
var phrase = "cde";
println(strstr(str,phrase));
// Outputs "-1". No occurrence was found.
var str = "abcdefghij";
var phrase = "xgj";
println(strstr(str,phrase));
// Outputs "15". After position 8, the first occurrence
// of the phrase is located at position 15.
var str = "abcdefghij abcdefghij";
var phrase = "efg";
var pos = 8;
println(strstr(str,phrase,pos));