showing only x number of characters

J

Joey Martin

I am using a WYSIWYG editor for articles and the article text is being
inserted into a SQL db field called ARTICLEBODY.

Question:
On my homepage, I only want to display the first 400 characters of
ARTICLEBODY field. I am using the LEN function and it does what I want.
BUT, is there a way to not have it cutoff in the middle of a word?
 
R

Ray Costanzo [MVP]

In your SQL query or using vbscript or jscript in your ASP page? If in your
query, what kind of database? If in your code, what relevant code snippet
are you currently using?

Ray at work
 
E

Evertjan.

Joey Martin wrote on 09 sep 2004 in
microsoft.public.inetserver.asp.general:
I am using a WYSIWYG editor for articles and the article text is being
inserted into a SQL db field called ARTICLEBODY.

Question:
On my homepage, I only want to display the first 400 characters of
ARTICLEBODY field. I am using the LEN function and it does what I want.
BUT, is there a way to not have it cutoff in the middle of a word?

Sure, many ways.

the nicest ones are in ASP jscript:

t = t.replace(/^(.{0,400}) .*$/,'$1')

or if you do not like regex:

t = t.substr(0,401).split(' ').slice(0,-1).join(' ')

tested, but not tested for exact 400 max
 

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

Forum statistics

Threads
474,161
Messages
2,570,891
Members
47,423
Latest member
henerygril

Latest Threads

Top