HTML and CSS Reference
EXPLANATION ( CONTINUED )
The charAt() method returns the character found at a specified position within a
string; in this example, position 0. Position 0 is the first character in the string, a
letter D .
By giving the charAt() method the length of the string minus 1, the last character
in the string is extracted, a letter g (see Figure 9.34).
Figure 9.34 The charAt() , split() , and substr() methods: Output from Example 9.29.
Search and Replace Methods. In word processing software you'll always find
some mechanism to search for patterns in strings and to replace one string with another.
method searches for a substring and returns the position where the substring is found
first. The match() method searches a string for substrings and returns an array contain-
ing all the matches it found. The replace() method searches for a substring and replaces
it with a new string. These methods are discussed again in Chapter 17, “Regular Expres-
sions and Pattern Matching,” in more detail.
<head><title>Search and Replace</title></head>
<font face="arial" size="+1">
Search and Replace Methods<br />
var straddr = "DanielSavage@dadserver.org";
document.write("The original string is "+ straddr
+ "<br />");
document.write( "The new string is "+
straddr.replace("Daniel","Jake") +"<br />");