Simple word count

  • Thread starter Thread starter Jonesgj
  • Start date Start date
J

Jonesgj

Hi,

Whats the best way to do a word count of the content of a rich text box?

Thanks in advance

Jones GJ
 
Jonesgj said:
Hi,

Whats the best way to do a word count of the content of a rich text box?

Thanks in advance


this is NOT the best way (it's actually an embarassing way) ... but you did
say "simple" and it may be good enough for your purposes:

dim wordcount as integer

dim a as string() = RichText.Text.Split(" ")

wordcount = a.length
 
Another simple way that creates way less number of objects:

wordcount = RichText.Text.Length - RichText.Text.Replace(" ",
string.Empty).Length
 
Thanks Liz,

I tried counting spaces before, and, even after checking for double spaces
found the accuracy decreased with the length of text being analysed
(dependent on quality of typing!)

Just wondered if there was something a liitle more accurate.

Thanks again
 
Jonesgj,

If I had not seen the method from Goran, I would have uses the overloaded
split (at the end there is no whitespace by instance).

http://msdn.microsoft.com/library/d...ef/html/frlrfsystemstringclasssplittopic1.asp

Now I think that even the great method as Goran shows, but than more times
done, will be much more efficient.

http://msdn.microsoft.com/library/d.../html/frlrfsystemstringclassreplacetopic1.asp

Be aware that you use this char method " "c because that is for sure much
faster than the replace string string method.

I hope this helps,

Cr
 
Hi Cr,

Followed the first link and yes, that is certainly million times better than
my previous efforts

Many thanks

Jonesg
 
Back
Top