467,174 Members | 1,340 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,174 developers. It's quick & easy.

COutn the number of words

how can i count how many words have i written in a text
area???

Like taking an example ... i am writing in this textarea
of microsoft usergroup. and say in total i have written 50
words .. how can find out this information?

thanks
Jul 19 '05 #1
  • viewed: 1850
Share:
2 Replies
You need to define what a word is. If all words are merely characters
separated by spaces, then you can just count the number of spaces in your
text-area, and add 1.

For example the following text:

The quick brown fox jumped over the lazy dog.

has 8 spaces. Add 1, and you get 9, which is the number of words. However,
judging by the quality of spelling et al in your post, this may not be an
entirely accurate measure of the number of words that you'd have typed into
a textarea.

Cheers
Ken

"janet" <kn*******@hotmail.com> wrote in message
news:42****************************@phx.gbl...
: how can i count how many words have i written in a text
: area???
:
: Like taking an example ... i am writing in this textarea
: of microsoft usergroup. and say in total i have written 50
: words .. how can find out this information?
:
: thanks
Jul 19 '05 #2
janet wrote on 08 sep 2003 in microsoft.public.inetserver.asp.general:
how can i count how many words have i written in a text
area???

Like taking an example ... i am writing in this textarea
of microsoft usergroup. and say in total i have written 50
words .. how can find out this information?


When you have submitted the string to serverside ASP
[If you want a clientside solution please go elsewhere]

first trim and change all multiple whitespace to single spaces,
then count your spaces and add one:

Serverside Jscript:

s = " blah blah blah "
s = s.replace(/(^\s+)|(\s+$)/g,"")
s = s.replace(/\s+/g," ")
s = s.split(" ")
l = s.length - 1 + 1

===================

more concise:

s = " blah blah blah "
l = s.replace(/(^\s+)|(\s+$)/g,"").replace(/\s+/g," ")
.split(" ").length
// make one line of the two above

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Alex Martelli | last post: by
9 posts views Thread by cw bebop | last post: by
5 posts views Thread by VJ | last post: by
4 posts views Thread by JaredEmery | last post: by
6 posts views Thread by Gary Wessle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.