Basic HTML version of Foils prepared 23 June 1997

Foil 43 JavaScript String Methods - II

From JavaScript Tutorial for Certificate Course UC Web applications Certificate -- Summer 97. by Geoffrey C. Fox, Tom Scavo


We introduce two new methods:
myString.IndexOf(lookfor);
where myString and lookfor are any strings
IndexOf returns the position of a character in myString that begins a substring exactly matching lookfor:
var s = "http://www.npac.syr.edu";
s.IndexOf("www"); // returns 7
myString.IndexOf(lookfor, searchfrom);
where searchfrom specifies the starting position of the search (see the previous foil for an example)
myString.lastIndexOf(lookfor, lastsearchfrom);
is similar to IndexOf but starts from the end of the string
Default value of lastsearchfrom is myString.length - 1
IndexOf and lastIndexOf return -1 if requested string is not found



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998