Chapter 6 Example 4

by actionscriptbible
♥0 | Line 21 | Modified 2009-06-16 04:11:58 | MIT License
play

ActionScript3 source code

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/69oC
 */

package {
  import com.actionscriptbible.Example;
  public class ch6ex4 extends Example {
    public function ch6ex4() {

      var names:String = "Jenene, Jake, Jason, Joey, Jaya";
      trace(names.indexOf("Jake"));   //8
      trace(names.lastIndexOf("J"));  //27
      trace(names.indexOf("Robert")); //-1

      var story:String = "It was a dark and stormy night...";
      var pattern:String = "a";
      var count:int = 0;
      var startIndex:int = 0;
      while (story.indexOf(pattern, startIndex) != -1) {
        count++;
        startIndex = story.indexOf(pattern, startIndex) + 1;
      }
      trace(story);
      trace("found " + count + " 'a's"); //Found 4 'a's

    }
  }
}

Forked