| Author |
Topic Search Topic Options
|
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
Topic: Trimming Words Posted: 21 February 2005 at 3:20pm |
I have a database field that is a memo type. I would like to be able to only display the first 50 words from the database. I would like for it to show ..... after about 50 words.
I am using <%=Content %>. How do I trim this field to show only 50 words and then ....?
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 February 2005 at 3:30pm |
Function LengthTrim(input, length)
If Len(input) > length Then
Return Left(input, length) + "..."
Else
Return input
End If
End Function
|
then <%= LengthTrim(Content, 50) %>
btw I don't guarentee that code will work - haven't coded in ASP for about 2 years
|
 |
Gullanian
Senior Member
Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 February 2005 at 3:31pm |
|
Well a rough estimate to the amount of words in the sentence is by
number of white space characters, so search for the position of the
50th whitespace character and cut it from there.
|
 |
Gullanian
Senior Member
Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 February 2005 at 3:32pm |
Mart,
Dont mean to sound critical but the function seems to just re-do the job of the left() function:
Function LengthTrim(input, length) Left(input, length)
Same difference, right? I think Misty wanted words anyway.
Edit: No actually you probably would want to use that function if its being called a lot. My mistake
Edited by Gullanian - 21 February 2005 at 3:33pm
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 February 2005 at 4:48pm |
I tried the following code:
Code:
Function LengthTrim(input, length)
If Len(input) > length Then
Return Left(input, length) + "..."
Else
Return input
End If
End Function
| | |
I also used <%= LengthTrim(Content, 50) %>
I got the following error message:
Microsoft VBScript runtime error '800a01f4'
Variable is undefined: 'Return'
There must be a typo. Can someone please help me with this?
Edited by Misty - 21 February 2005 at 4:49pm
|
 |
Gullanian
Senior Member
Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 February 2005 at 5:28pm |
Replace return line with
LengthTrim = input
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 21 February 2005 at 5:31pm |
told you I hadn't used ASP for 2 years
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
Posted: 22 February 2005 at 12:11am |
I got the following code to work:
Function LengthTrim(input, length) If Len(input) > length Then LengthTrim = Left(input, length) + "..." Else LengthTrim = input End If End Function
However, I have decided that I would like to trim words after 4 paragraphs. How can I accomplish this? The end tags for paragraphs are </p>. Can someone please help me with this?
|
 |