Page Views

Sunday, 25 November 2012

Character Counter

friends aap ko pata hoga ke jahan bhi aap test dene jate ho to aap ko typing ke liye word dete hain ke ye aap ko 30 minutes mein itne characters ye words likhne hain aaj main aap ko aik code de raha hoon jis se apne type kiye gaye words ko easily count kar sakte hain hain.


aur ziyada tar hum fourm ya website pe hum jo paragraph likhte hain unke kam se kam 500 tak character hona chahye to hamen kaise pata chale ga ke hum jo words likhe hain wo kitne hain, ye aap ko code boht helful sabit hoga. Counter calculator ka ye code aap kahen bhi HTML/JAVASCRIPT mein laga sakte hain.

Code yeh hain


Word/Line Count Calculator
<script type="text/javascript">
function calcStats()
{
var myString;
var lines;
var characters;
var words;
var charsnospaces;
var myString = document.getElementById("doc").value;
var trReturn = myString[myString.length-1] == "\n";

if (myString == "")
lines = characters = words = charsnospaces = 0;
else
{
lines = myString.split("\n").length; //counts the amount of lines.
if (trReturn)
lines--;
myString = myString.replace(/\n/g, " "); //replaces the line break characters with a space
characters = trReturn ? myString.length - lines : myString.length; //gets the length of the string with no line break characters.
myString = myString.replace(/^\s*|\s*$/g,""); //trim whitespace
myString = myString.replace(/\s{2,}/g," "); //eliminates extra whitespace around words.
words = myString.split(" ").length; //gets the words
myString = myString.replace(/\s/g, ""); //eliminates the spaces
charsnospaces = myString.length;
}

document.getElementById("lines").innerHTML = lines;
document.getElementById("characters").innerHTML = characters;
document.getElementById("words").innerHTML = words;
document.getElementById("charsnospaces").innerHTML = charsnospaces;
}
function clearSpans()
{
document.getElementById("lines").innerHTML = "";
document.getElementById("characters").innerHTML = "";
document.getElementById("words").innerHTML = "";
document.getElementById("charsnospaces").innerHTML = "";
}
</script>
<form onreset="clearSpans()" style="margin:0">
  <textarea cols="30" id="doc" onchange="calcStats()" rows="5"></textarea>
  <br />
  <input onclick="calcStats()" type="button" value="Get Stats" />
  <input type="reset" value="Clear" />
</form>
<p class="result">Word count: <span id="words"></span></p>
<p class="result">Characters w/o spaces: <span id="charsnospaces"></span></p>
<p class="result">Characters: <span id="characters"></span></p>
<p class="result">Lines: <span id="lines"></span></p>

<script>gadgets.util.runOnLoadHandlers();</script><script>window.google.csi.tickDl();
</script>


1 comments:

Siska said...

aduayam

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Bluehost Coupons