Odd how I ended up parsing this html in actionscript by changing a counting function.. and I even backtracked to AS 2.0.. well thats my strong point.. Im still really not use to Actionscript 3.0.. so Im.. making my first AS 3.0 profile biggrin
So heres the code tangent
Got this off Kurpa cant remember exactly.. but eh..
//count("somestring", "letter") //function count(s : String, letter : String) : int { // return s.match(new RegExp(letter,"g")).length; //}
Heres where I went with that.. //Modded counting function to do more than count a one letter string.. /*function count(str:String, char:String):Number { var count:Number=0; for (var i=0; i < str.length; i++) { var CHECKPOINT:Number=str.indexOf(char, i) if (CHECKPOINT>=0) { trace("CHECKPOINT: "+CHECKPOINT+" of "+char) count++; i=CHECKPOINT+1; } } return count; }*/
Final product was this neat little crude function.. function CCEvall(str:String, charA:String, charB:String):Number { ///Count_Compair_eval or CCEvall var count:Number=0; var index:Number=0; var CHECKPOINT:Number; for (var i1=0; i1 < str.length; i1++) { CHECKPOINT=str.indexOf(charA,i1) if (CHECKPOINT>=0) { trace("CHECKPOINT: "+CHECKPOINT+" of "+charA) count++; index=CHECKPOINT; i1=CHECKPOINT+1; } } for (var i2=0; i2 < str.length; i2++) { CHECKPOINT=str.indexOf(charB,i2) if (CHECKPOINT>=0&&count>0) { trace("CHECKPOINT: "+CHECKPOINT+" of "+charB) count--; i2=CHECKPOINT+1; index=CHECKPOINT; } } return index; }
And some random bits an the end of my Action script panel.. hmm :/ dont know how they got there.. sweatdrop
//trace(countOccurences(str, char))//Outputs 2
Sadorath · Fri Jan 28, 2011 @ 04:29am · 0 Comments |