String.length Property

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
String.length Property Flash 5

the number of characters in a string read-only
string.length

Description

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)

Example

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"); }

See Also

Array.length( ); "The length property," in Chapter 4



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net