Home All Groups Group Topic Archive Search About
Author
6 May 2006 6:00 AM
Jonesgj
Hi,

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

Thanks in advance

Jones GJ

Author
6 May 2006 7:32 AM
Liz
"Jonesgj" <a@b.com> wrote in message news:If-dnbIxtMV7p8HZRVnyjg@bt.com...
> 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
Author
6 May 2006 9:14 AM
Göran_Andersson
Another simple way that creates way less number of objects:

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

Liz wrote:
Show quoteHide quote
> "Jonesgj" <a@b.com> wrote in message news:If-dnbIxtMV7p8HZRVnyjg@bt.com...
>> 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
Author
6 May 2006 9:20 AM
Jonesgj
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


Show quoteHide quote
"Liz" <liz@no-spam.org> wrote in message
news:viY6g.340882$hn5.28319@fe04.news.easynews.com...
>
> "Jonesgj" <a@b.com> wrote in message news:If-dnbIxtMV7p8HZRVnyjg@bt.com...
>> 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
>
>
>
>
Author
6 May 2006 10:24 AM
Cor Ligthert [MVP]
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/default.asp?url=/library/en-us/cpref/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/default.asp?url=/library/en-us/cpref/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



Show quoteHide quote
"Jonesgj" <a@b.com> schreef in bericht news:vZednfH29fFW9MHZRVny2Q@bt.com...
> 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
>
>
> "Liz" <liz@no-spam.org> wrote in message
> news:viY6g.340882$hn5.28319@fe04.news.easynews.com...
>>
>> "Jonesgj" <a@b.com> wrote in message
>> news:If-dnbIxtMV7p8HZRVnyjg@bt.com...
>>> 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
>>
>>
>>
>>
>
>
Author
6 May 2006 4:40 PM
Jonesgj
Hi Cr,

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

Many thanks

Jonesg

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23XsLOcPcGHA.536@TK2MSFTNGP02.phx.gbl...
> 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/default.asp?url=/library/en-us/cpref/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/default.asp?url=/library/en-us/cpref/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
>
>
>
> "Jonesgj" <a@b.com> schreef in bericht
> news:vZednfH29fFW9MHZRVny2Q@bt.com...
>> 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
>>
>>
>> "Liz" <liz@no-spam.org> wrote in message
>> news:viY6g.340882$hn5.28319@fe04.news.easynews.com...
>>>
>>> "Jonesgj" <a@b.com> wrote in message
>>> news:If-dnbIxtMV7p8HZRVnyjg@bt.com...
>>>> 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
>>>
>>>
>>>
>>>
>>
>>
>
>
Author
6 May 2006 6:34 PM
cj
I'd like to take credit for it but this is found on page 3 of the
article at http://www.ftponline.com/vsm/2003_01/magazine/features/balena/

..... the \w+ regular expression matches any word, so you count the words
in a source string with only two statements:

Dim text As String = "Here is a sample sentence"
Dim re As New Regex("\w+")
Console.WriteLine( _
    re.Matches(text).Count)   ' => 5



Jonesgj wrote:
Show quoteHide quote
> Hi,
>
> Whats the best way to do a word count of the content of a rich text box?
>
> Thanks in advance
>
> Jones GJ
>
>