Flash / Flex / ActionScript/String/char code

Материал из Web эксперт
Перейти к: навигация, поиск

Converting a Character to a Character Code

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
         var band:String = "MC";
         trace(band.charCodeAt(1));
    }
  }
}



Getting a Character Code: charCodeAt() takes an index within the string, then returns the character code for the character at that index.

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var sTitle:String = new String("ActionScript Bible");
        trace(sTitle.charCodeAt(12));  // Displays: 32

    }
  }
}



The fromCharCode() method is a static method of the String class. returns a new string primitive value with the character that corresponds to the character code.

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        for(var i:Number = 0; i < 150; i++){
           trace(i + ": " + String.fromCharCode(i));
        }
    }
  }
}