Simple Seo Solutions
SEO and Promotion sites
VoiceNotebook.com
Speech to text for Android
|
|
Word counting with javascript
This simple script counts number of symbols and words in some text. This script consideres the word as
any combination of not white space letters.
Here the code of the script:
function isWhiteSymbol(symb)
{
var ret = false;
switch(symb)
{
case " ":
case "":
case"\n":
case "\r":
ret = true;
default:
}
return ret;
}
function Button1_onclick() {
var sometext = document.getElementById("TextArea1").value;
var somelen =sometext.length.toString(10);
var wordcount = 0;
var colnotwhite = 0;
var wordbegin = false;
for(var i=0;i < somelen; i++)
{
if( !isWhiteSymbol(sometext.charAt(i)) )
{
colnotwhite = colnotwhite + 1;
if(wordbegin == false)
{
wordcount= wordcount+1;
wordbegin = true;
}
}
else
{
wordbegin = false;
} // end if(sometext.charAt(i) != ' ')
}//end for
alert("Symbols = " + somelen + "\nSymbols in words = " +
colnotwhite.toString(10) + "\nWords = " + wordcount.toString(10));
}//end function
Try this examle
|
|
|
|