Flash / Flex / ActionScript/Array/split

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

Converting a String to an Array: Use the String.split(delimiter, maximum_number_of_elements_to_place_into_the_new_array) method.

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var list:String = "Piper picked a peck of pickled peppers";
        var words:Array = list.split(" ");
        
        trace(words);
    }
  }
}



The split() method asks that you specify the delimiter it should use to determine the elements of the list

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var sEmployees:String = "A,P,C,H";
        var aEmployees:Array = sEmployees.split(",");
        trace(aEmployees); 
    }
  }
}