|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple word countHi,
Whats the best way to do a word count of the content of a rich text box? Thanks in advance Jones GJ "Jonesgj" <a@b.com> wrote in message news:If-dnbIxtMV7p8HZRVnyjg@bt.com... this is NOT the best way (it's actually an embarassing way) ... but you did > Hi, > > Whats the best way to do a word count of the content of a rich text box? > > Thanks in advance 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 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 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 > > > > 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 >> >> >> >> > > 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 >>> >>> >>> >>> >> >> > > 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 > >
single to string problem
Error setting CSV to display text Simple TCP communications examples Thread terminating instantly How to move the mouse around in vb.net Invalid format of DLL How do I take a screenshot in VB.net 2005 Move emails (.msg files) between an Outlook inbox and a file direc How to simulate mouse click in vb.net My.Settings object set setting by name? |
|||||||||||||||||||||||