Use indexOf( ) in a while statement to get the indices of every occurrence of a substring : IndexOf lastIndexOf : String Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » String » IndexOf lastIndexOf »

 

Use indexOf( ) in a while statement to get the indices of every occurrence of a substring


 

package{
  import flash.display.Sprite;
  
  public class Main extends Sprite{
    public function Main(){
        var example:String = "This string contains the word cool. Very cool. Yes, cool.";
        var index:int =  -1;
        while ( ( index = example.indexOf"cool", index + ) ) != -) {
        
          trace"String contains word cool at index " + index );
        }
    }
  }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo String
» IndexOf lastIndexOf