Befor MapReduce
♥0 |
Line 34 |
Modified 2009-09-03 14:57:04 |
MIT License
archived:2017-03-20 07:41:16
ActionScript3 source code
/**
* Copyright pasodania ( http://wonderfl.net/user/pasodania )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zItl
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite{
public var output:TextField;
public var swCnt:SimpleWordCounter;
public function Main() {
// write as3 code here..
output = new TextField();
swCnt = new SimpleWordCounter("abacaszca");
output.appendText(swCnt.getCharCount("ca").toString());
addChild(output);
}
}
}
import flash.display.Sprite;
import flash.text.TextField;
class SimpleWordCounter{
private var _target:String;
public function SimpleWordCounter(target:String){
_target = target;
}
public function getCharCount(w:String):int{
var now:int = 0;
var result:int = 0;
while( now <= _target.length){
if( _target.indexOf(w, now) != -1 ){
result++;
now = _target.indexOf(w, now);
}
now++;
}
return result;
}
}