Important alert: (current site time 7/15/2013 10:59:52 PM EDT)
 

VB icon

ASP Teaser Text

Email
Submitted on: 7/13/2001 6:35:09 AM
By: Jason Slater  
Level: Beginner
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 10452
author picture
(About the author)
 
     Pass this Function a string and it will return the first 'n' words.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: ASP Teaser Text
' Description:Pass this Function a string and it will return the first 'n' words.
' By: Jason Slater
'
' Inputs:String - The Full Text String
Integer - The Number of Words to return
'
' Returns:Returns the first 'n' words of the passed string with ... appended.
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6769&lngWId=4'for details.'**************************************

<%
' This is some example text
strText = "This is some example text to prove the get teaser function"
' This is an example call to function pass it phrase and number of words to return
Response.Write GetTeaser(strText,9)
' This is the function, pass it the phrase, it returns the first 'n' words.
Function GetTeaser(strText,iWords)
Dim strTaster
Dim iCount
strTaster = ""
iCount = 0
While (iCount < iWords)
	strWord = Left(strText,Instr(strText," "))
	strTaster = strTaster & " " & strWord
	strText = Right(strText,Len(strText)-Len(strWord))
	iCount = iCount + 1
Wend
If strTaster <> "" Then strTaster = strTaster & "..."
GetTeaser = strTaster
End Function
%>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
7/13/2001 8:42:52 AMSven Moderow

And what about HTML-Tags that could be within the String???
(If this comment was disrespectful, please report it.)

 
7/16/2001 11:47:46 AMmgfranz

Simple, just strip out the characters and everything enclosed within <> using RegExp().

But then again, if I was to use this code, it would be against my own dB entries, and the HTML code would long be removed...

Nice function Jason.
(If this comment was disrespectful, please report it.)

 
1/19/2003 1:35:18 PMmiracl

there is a much simplier solution
fullStr="This is some example text To prove the Get teaser function"


function teaser(aStr,aNumber)
tmpArray=split(aStr," ")
redim preserve tmpArray(8)
teaser=join(tmpArray," ")&"..."
end function

don t you think ?
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.