469,602 Members | 1,940 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Classic ASP text input word count problem???

I am trying to build an asp page the displays 100 characters from text
inputed into a text area. The page keeps breaking because it counts any HTML
code the text might have. I would like to have it count the words instead and
when I write out the words it includes any underlying html.

For example, here is a sentence: "The fox jumps over the lazy dog" and I
could cut this sentence in half by counting out the first 18 character and
only outputing those respectively. Everything would work just fine. But if
the sentence is like this "The fox jumps <a href='http://www.microsoft.com'
target='_blank'>over</a> the lazy dog." a simple letter count no longer works
for me. If I printed out the first 18 characters then it will break my "href"
tag and therefore would mess up the formatting of my page. Can someone point
me to an article or component that will assist me in correcting this? Thanks!

Eddie
Feb 15 '06 #1
1 2465
=?Utf-8?B?YWR1ZGUyOA==?= wrote on 15 feb 2006 in
microsoft.public.inetserver.asp.general:
For example, here is a sentence: "The fox jumps over the lazy dog" and
I could cut this sentence in half by counting out the first 18
character and only outputing those respectively. Everything would work
just fine. But if the sentence is like this "The fox jumps <a
href='http://www.microsoft.com' target='_blank'>over</a> the lazy
dog." a simple letter count no longer works for me. If I printed out
the first 18 characters then it will break my "href" tag and therefore
would mess up the formatting of my page. Can someone point me to an
article or component that will assist me in correcting this? Thanks!


<script runat=server language=jscript>

s = "The fox jumps <a href='http://www.microsoft.com' "+
"target='_blank'>over</a> the lazy dog.";

wordCount = s.replace(/<[^>]*>/g,'').split(' ').length; // 7

response.write('The number of words is ' + wordCount);

</script>

nothing is perfect though, this will fail:

.... <a href='..' alt='Less than is written ">"'> ...
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by dan | last post: by
8 posts views Thread by FUGATO | last post: by
1 post views Thread by samoukos | last post: by
21 posts views Thread by arnuld | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.