[thelist] ASP: First 100 words in a record

Warden, Matt mwarden at mattwarden.com
Wed Jun 19 10:44:00 CDT 2002


On Jun 19, Ken Kogler had something to say about [thelist] ASP: First 100...

>hola, evolt amigos...
>
>Using ASP, is there a way to limit the number of words returned in a
>recordset?
>
>Simple example: I've got a CMS that deals with articles. On the home page, I
>want to show the first 100 words or so of every article with a "click here
>to read the full text" link afterward.
>
>Is there an easier way to do this (both on me and on the server) than to
>string concatenation? I thought about just looking for the first </p> in the
>field, but sometimes that can be only a few words into the article.
>
>evolt.org does this on the homepage, but they're using a separate db field
>for a descriptive paragraph (think they call it a synopsis). I could do it
>this way, too, but it requires mods to the db, and that's not something the
>client is prepared to let me do. I'm just supposed to pretty up the
>front-end.

the synopsis used to be the first x characters of the article.

if it doesn't have to be the first 100 *words*, then this is simple:

sSynopsis = trim(Left(sArticleBody, 500)) & "..."

this will get the first 500 characters of sArticleBody, trim any spaces,
and then concatenate "..."

you want to trim so you don't get:

"red monkeys are livlier than ..."

but rather

"red monkeys are livlier than..."

if you want 100 words instead, i can't see any other way than:

split() the string on a space
keep only first 100 array items
join() with a space

but i'd think this is a nightmere as far as resources go.

you could roll your own loop that uses mid() and instr(), too. let me know
if you want some help with that. but i suspect the "first x
chars" solution will be fine.

--
mattwarden
mattwarden.com




More information about the thelist mailing list