473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Simple word count

Hi,

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

Thanks in advance

Jones GJ
May 6 '06 #1
6 2704
Liz

"Jonesgj" <a@b.com> wrote in message news:If********************@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


May 6 '06 #2
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" <li*@no-spam.org> wrote in message
news:vi********************@fe04.news.easynews.com ...

"Jonesgj" <a@b.com> wrote in message news:If********************@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

May 6 '06 #3
Another simple way that creates way less number of objects:

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

Liz wrote:
"Jonesgj" <a@b.com> wrote in message news:If********************@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

May 6 '06 #4
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/de...plittopic1.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/de...lacetopic1.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:vZ********************@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" <li*@no-spam.org> wrote in message
news:vi********************@fe04.news.easynews.com ...

"Jonesgj" <a@b.com> wrote in message
news:If********************@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


May 6 '06 #5
Hi Cr,

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

Many thanks

Jonesg

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2***************@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/de...plittopic1.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/de...lacetopic1.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:vZ********************@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" <li*@no-spam.org> wrote in message
news:vi********************@fe04.news.easynews.com ...

"Jonesgj" <a@b.com> wrote in message
news:If********************@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



May 6 '06 #6
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...atures/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:
Hi,

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

Thanks in advance

Jones GJ

May 6 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Lucas-Smith | last post by:
I am trying to use PHP's COM support to open a URL from within MS Word then save the document. I am using PHP5.0.3/Apache2/WindowsXP. phpinfo() confirms that COM support is enabled. ...
5
by: jester.dev | last post by:
Hello, I'm learning Python from Python Bible, and having some problems with this code below. When I run it, I get nothing. It should open the file poem.txt (which exists in the current...
7
by: dan | last post by:
hey peeps, i am completely new at c++ and i need some help with an assignment. it is basically about file i/o with fstreams. i understand how to open a file with fstream, but how would you read,...
1
by: vmoreau | last post by:
I have a text and I need to find a Word that are not enclosed in paranthesis. Can it be done with a regex? Is someone could help me? I am not familar with regex... Example looking for WORD:...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
1
by: nearestniladri2003 | last post by:
#include <stdio.h> #include <conio.h> void main() { FILE *fp; char a,data;//Just taking 100 bytes not more that that. int i = 0,count = 0; fp = fopen("C:\\mydoc.txt","r"); // Here my...
1
by: beanie | last post by:
i am a c programming beginner and i am trying to Create a concordance of Word Count for a text File in c programming but my code isn't working.please can u help me out.here is my code: #include...
2
by: beanie | last post by:
i am a beginer in c programming and i am trying to Create a Concordance of Word Count for a Text File but my code is not working.pls can anyone helpme out.here is my code: #include <stdio.h>...
6
by: boyindie86 | last post by:
Hi I have been fighting with this lump of code for the last week what I am trying to do is that I am passing words into passages of texts, and I want the system to go and find exact word matches...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.