May 2001
Intermediate to advanced
720 pages
23h 24m
English
String.length Property — the number of characters in a string
Flash 5
string.length
Read-only
The length property returns the number of
characters in string. Note that a null
character (ASCII 0) does not signal the end of a string, as it would
in some languages, but neither is it counted in the string’s
length. For example:
// Create the string "A" + null + "B" var myString = String.fromCharCode(65,0,66); trace(myString.length); // Displays: 2 (The null character is ignored)
var myString = "hello";
trace (myString.length); // Displays: 5
trace ("hello".length); // Displays: 5
// Here we convert the number 1000 to a
// string in order to test its length
var age = 1000;
// Display an error message if the number has the wrong number of digits.
if (String(age).length != 2) {
trace ("Please enter a two-digit number");
}
Array.length( ); Section 4.6.5.1 in Chapter 4
Read now
Unlock full access