Flash / Flex / ActionScript/String/search

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

Searching

 
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var reCase:RegExp = new RegExp("\\s(\\w)+\\s", "g");
        var sValue:String = new String("abc def ghi");
        trace(sValue.search(reCase));                // 3
    }
  }
}



String.search(pattern:*):int

 
Call search() on a String to find the first occurrence of the pattern you pass it.
package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var themTharHills:String = "hillshillshillsGOLDhills";
        trace(themTharHills.search("/gold/i")); //15
    }
  }
}