Basic HTML version of Foils prepared 23 June 1997

Foil 40 JavaScript String Objects - I

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


1 Any constant such as "Hello World!" or a variable holding text is a String object in JavaScript. For example:
2 /* Add stem to newurl if the latter is a relative
3 address. Stem must end with a slash. */
4 function checkurl(stem, newurl) {
5 var len = newurl.length; // length property of String
6 var stemlen = stem.length;
7 if ( len < 7 )
  • return (stem + newurl); // URL is not absolute
8 var grab = newurl.substring(0,6); // first six chars
9 if( (grab == "ftp://") || (grab == "http:/") )
  • return newurl; // URL IS absolute!
10 return (stem + newurl);
11 }
12 function seturl(name) {
13 var addr = "http://www.npac.syr.edu/users/gcf/wisdom/";
14 name.href = checkurl(addr, "List.html");
15 }

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