Class String

Object
  extended by String

public class String
extends Object

An object representing a series of characters in a string. The String object is a wrapper around the string primitive data type. Do not confuse a string literal with the String object.


Field Summary
 Number length
          Reflects the length of the string.
 
Method Summary
 String charAt(Number index)
          Returns the specified character from the string.
 Number charCodeAt(Number index)
          Returns a number indicating the Unicode value of the character at the given index.
 String fromCharCode(Number... charCode)
          Returns a string created by using the specified sequence of Unicode values.
 Number indexOf(String searchValue, Number fromIndex)
          Returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex, or -1 if the value is not found.
 Number lastIndexOf(String searchValue, Number fromIndex)
          Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found.
 String[] match(RegExp regexp)
          Used to match a regular expression against a string.
 String[] replace(RegExp regexp, String newSubStr, Function func)
          Finds a match between a regular expression and a string, and replaces the matched substring with a new substring.
 String substring(Number start, Number end)
          Returns a subset of a String object.
 String toLowerCase()
          Returns the calling string value converted to lowercase.
 String toUpperCase()
          Returns the calling string value converted to uppercase.
 
Methods inherited from class Object
toString
 

Field Detail

length

public Number length
Reflects the length of the string.

Method Detail

replace

public String[] replace(RegExp regexp,
                        String newSubStr,
                        Function func)
Finds a match between a regular expression and a string, and replaces the matched substring with a new substring. This method does not change the String object it is called on. It simply returns a new string. If you want to execute a global search and replace, include the g flag in the regular expression.

Parameters:
regexp - Name of the regular expression. It can be a variable name or a literal.
newSubStr - The string to put in place of the string found with regexp.
func - A function to be invoked after the match has been performed.

toUpperCase

public String toUpperCase()
Returns the calling string value converted to uppercase. The toUpperCase method returns the value of the string converted to uppercase. toUpperCase does not affect the value of the string itself.


fromCharCode

public String fromCharCode(Number... charCode)
Returns a string created by using the specified sequence of Unicode values. This method returns a string and not a String object. Because fromCharCode is a static method of String, you always use it as String.fromCharCode(), rather than as a method of a String object you created.

Parameters:
charCode - An integer between 0 and 1 less than the length of the string. The default value is 0.

charCodeAt

public Number charCodeAt(Number index)
Returns a number indicating the Unicode value of the character at the given index. Unicode values range from 0 to 65,535. The first 128 Unicode values are a direct match of the ASCII character set.

Parameters:
index - An integer between 0 and 1 less than the length of the string. The default value is 0.

toLowerCase

public String toLowerCase()
Returns the calling string value converted to lowercase. The toLowerCase method returns the value of the string converted to lowercase. toLowerCase does not affect the value of the string itself.


substring

public String substring(Number start,
                        Number end)
Returns a subset of a String object.

Parameters:
start - An integer between 0 and 1 less than the length of the string.
end - An integer between 0 and 1 less than the length of the string.

lastIndexOf

public Number lastIndexOf(String searchValue,
                          Number fromIndex)
Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found. The calling string is searched backward, starting at fromIndex. Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character is stringName.length - 1.

Parameters:
searchValue - A string representing the value to search for.
fromIndex - The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is the length of the string.

match

public String[] match(RegExp regexp)

Used to match a regular expression against a string.

If the regular expression does not include the g flag, returns the same result that RegExp.exec would return on the regular expression and string. If the regular expression includes the g flag, returns an array of all the matches of the regular expression in the string.

Note If you execute a match simply to find true or false, use String.search or the regular expression test method.

Parameters:
regexp - Name of the regular expression. It can be a variable name or a literal.

indexOf

public Number indexOf(String searchValue,
                      Number fromIndex)
Returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex, or -1 if the value is not found. Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character of a string called stringName is stringName.length - 1.

Parameters:
searchValue - A string representing the value to search for.
fromIndex - The location within the calling string to start the search from. It can be any integer between 0 and the length of the string. The default value is 0.

charAt

public String charAt(Number index)
Returns the specified character from the string. Characters in a string are indexed from left to right. The index of the first character is 0, and the index of the last character in a string called stringName is stringName.length - 1. If the index you supply is out of range, JavaScript returns an empty string.

Parameters:
index - An integer between 0 and 1 less than the length of the string.