Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Trimming Words
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Trimming Words

 Post Reply Post Reply Page  123>
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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 ....?
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 21 February 2005 at 5:28pm
Replace return line with

LengthTrim = input

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 21 February 2005 at 5:31pm
told you I hadn't used ASP for 2 yearsSmile
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
 Post Reply Post Reply Page  123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.