views:

78

answers:

2

consider, in my javascript i am getting :

function callBack_Show(result) {
//where result is in jsonp format

var artical= result.Artical;

now artical contains some text,

i want to read number of words and characters in it and display them the words can be separated by: blank space, fullstop,comma etc and i want to do it in same javascript function (callBack_Show(result) )

+1  A: 

To calculate the number of words you want to use the String.split() method, and then use the length property of the resultant Array. To count the number of characters use the String.length property.

jonchang
+3  A: 

To get the number of words, you can split the text using a regular expression where you can define what is your criteria for separating words.

To get the number of characters, you can use the length property of the String, eg.:

var words = artical.split(/[\s.,]/).length; // whitespace, dot and comma
var characters = artical.length;
CMS
i have an addition to this problemin above example result.artical would be HTML text for ex.<div class="StoryArticleInfo"><p><p>BODY Article By Archie(Used By Story Tool)</p>and i want to read number of actual text words and charactersie:BODY Article By Archie(Used By Story Tool)pls help, thank you
dexter