Welcome to Gaia! :: View User's Journal | Gaia Journals

 
 

View User's Journal

Report This Entry Subscribe to this Journal
Private Log
Odd tangents I go on when I code
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
Community Member
  • [08/21/19 07:56pm]
  • [07/31/19 12:16am]
  • [07/27/19 01:30pm]
  • [07/26/19 06:13pm]
  • [01/06/17 04:13am]
  • [02/27/12 12:07am]
  • [02/24/12 02:24am]
  • [02/20/12 02:53am]
  • [12/07/11 04:02am]
  • [10/27/11 05:54pm]



  •  
     
    Manage Your Items
    Other Stuff
    Get GCash
    Offers
    Get Items
    More Items
    Where Everyone Hangs Out
    Other Community Areas
    Virtual Spaces
    Fun Stuff
    Gaia's Games
    Mini-Games
    Play with GCash
    Play with Platinum