S > String (object)
String (object)
The String object is a wrapper for the string primitive data type, which allows you to use the methods and properties of the String object to manipulate primitive string value types. You can convert the value of any object into a string using the String()
function.
All of the methods of the String object, except for concat
, fromCharCode
, slice
, and substr
, are generic. This means the methods themselves call this.toString
before performing their operations, and you can use these methods with other non-String objects.
You can call any of the methods of the String object using the constructor method new String
or using a string literal value. If you specify a string literal, the ActionScript interpreter automatically converts it to a temporary String object, calls the method, and then discards the temporary String object. You can also use the String.length
property with a string literal.
It is important that you do not confuse a string literal with an instance of the String object. In the following example the first line of code creates the string literal s1
, and the second line of code creates an instance of the String object s2
.
s1 = "foo"
s2 = new String("foo")
It is recommended that you use string literals unless you specifically need to use a String object, as String objects can have counterintuitive behavior.
Returns a number corresponding to the placement of the character in the string. Returns the value of the character at the given index as a 16-bit integer between 0 and 65535. Combines the text of two strings and returns a new string. Returns a string made up of the characters specified in the arguments. Searches the string and returns the index of the value specified in the arguments. If value occurs more than once, the index of the first occurrence is returned. If value is not found, -1 is returned. Returns the last occurrence of substring within the string that appears before the start position specified in the argument, or -1 if not found. Extracts a section of a string and returns a new string. Splits a String object into an array of strings by separating the string into substrings. Returns a specified number of characters in a string, beginning at the location specified in the argument. Returns the characters between two indexes, specified in the arguments, into the string. Converts the string to lowercase and returns the result. Converts the string to uppercase and returns the result.
Method summary for String object
Method
Description
charAt
charCodeAt
concat
fromCharCode
indexOf
lastIndexOf
slice
split
substr
substring
toLowerCase
toUpperCase
Returns the length of the string.
Property summary for the String object
Property
Description
length
Constructor for the String object
Syntax
new String(
value
);
Arguments
value
The initial value of the new String object.
Description
Constructor; creates a new String object.
Player
Flash 5 or later.
See also
String (function) " " (string delimiter)