String.length Property | Flash 5 |
the number of characters in a string | 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 (such as C), 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( ); "The length property," in Chapter 4