Flash / Flex / ActionScript/String/charAt — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 08:14, 26 мая 2010
charAt() takes one parameter, a value for an index within the string. This method returns a new one-character string that contains the value of the character at the specified index.
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var sTitle:String = new String("ActionScript");
var sChar:String = sTitle.charAt(0);
}
}
}
Retrieving One Character at a Time
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var example:String = "a string";
for ( var i:int = 0; i < example.length; i++ ) {
trace( example.charAt( i ) );
}
}
}
}
Use of a for loop to loop through the characters of a string, one at a time
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var sTitle:String = new String("ActionScript");
for (var i:Number = 0; i < sTitle.length; i++){
trace(sTitle.charAt(i));
}
}
}
}
A
c
t
i
o
n
S
c
r
i
p
t