Classic ASP text input word count problem???

A

adude28

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
 
E

Evertjan.

=?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 ">"'> ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top