Archive for February 16th, 2008

16
Feb

Word Count

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Returns the number of words in a string.

function wordcount(string:String):Number {
   var wrdArray:Array = string.split(" ");
   for (var i = wrdArray.length; i>0; i--) {
      if (wrdArray[i] == "") {
         wrdArray.splice(i,1);
      }
   }
   return wrdArray.length;
}
trace(wordcount("This will count the number of words"));

Found this useful? How about buying me a coffee - simply click here.




Close
E-mail It