Flash / Flex / ActionScript/String/char code — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:14, 26 мая 2010
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));
}
}
}
}