| home / programming / java_core / 2 | [previous] [next] |
|
|
There are two types of string methods: the string formatting methods that mimic the HTML tags they are named for, and the methods used to manipulate a string such as finding a position in a string, replacing a string with another string, making a string uppercase or lowercase, and the like.
Table 9.9 lists methods that will affect the appearance of a String object by applying HTML tags to the string, for example, to change its font size, font type, and color. Using these methods is a convenient way to change the style of a string in a JavaScript program, much easier than using quoted HTML opening and closing tags.
|
|
|---|
|
<head><title>String object</title> <h2>Working with String Objects:</h2> <script language="JavaScript"> 1 var str1 = new String("Hello world!"); // Use a String constructor 2 var str2 = "It's a beautiful day today."; document.write(str1) + "<br>"; 3 document.write(str1.fontcolor("blue")+"<br>"); 4 document.write(str1.fontsize(8).fontcolor("red"). 5 document.write(str1.big()+ "<br>"); |
|
|
|---|
A String object is created with the String() constructor. |
|
There are a number of methods (see Table 9.10) provided to manipulate a string.
|
Returns the Unicode encoding of the character at a specified index position |
|
|
Concatenates string arguments to the string on which the method was invoked |
|
|
Creates a string from a comma-separated sequence of character codes |
|
|
Searches for first occurrence of substr starting at startpos and returns the startpos(index value) of substr |
|
|
Searches for last occurrence of substr starting at startpos and returns the startpos (index value) of substr |
|
|
Searches for the regular expression and returns the index of where it was found |
|
|
Returns string containing the part of the string from startpos to endpos |
|
|
Returns a subset of string starting at startpos up to, but not including, endpos |
|
| home / programming / java_core / 2 | [previous] [next] |
| ||||||||||||||||||||
Created: March 27, 2003
Revised: November 19, 2003
URL: http://webreference.com/programming/java_core/2