HTML and CSS Reference
In-Depth Information
EXPLANATION
1
A
String
object is created with the
String()
constructor.
2
A string primitive is created the literal way.
3
The
fontcolor()
method is used to change the color of the string to blue. This
method emulates the HTML tag, <
font color=“blue”>.
4
The
fontsize()
,
fontcolor()
, and
bold()
methods are used as properties of the string.
5, 6
The HTML method is concatenated to the string
“Good-bye, ”
causing it to be dis-
played in italic, bold, large text (see Figure 9.30).
Figure 9.30
Properties of the
String
object are used to change its appearance and
determine its size.
There are a number of methods (see Table 9.10) provided to manipulate a string.
Table 9.10
Methods for String Manipulation
Method
What It Does
charAt(index)
Returns the character at a specified index position.
charCodeAt(index)
Returns the Unicode encoding of the character at a
specified index position.
concat(string1, ..., stringn)
Concatenates string arguments to the string on which the
method was invoked.
fromCharCode(codes)
Creates a string from a comma-separated sequence of
character codes.
indexOf(substr, startpos)
Searches for the first occurrence of
substr
starting at
startpos
and returns the
startpos(index value)
of
substr.
lastIndexOf(substr, startpos)
Searches for the last occurrence of
substr
starting at
startpos
and returns the
startpos (index value)
of
substr.
replace(searchValue, replaceValue)
Replaces
searchValue
with
replaceValue.
Continues