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


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

in Table To:


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