Home > ASP Programming > Displaying the first two hundred words

Displaying the first two hundred words



Hello gud pple of the forum,

How do i use asp to retrieve the first two hundred words from a field in a database.

Cheers

    
Guest


you can use a function to do this:


Code:


function countWords(varString, varWords)
'Start by trimming leading/trailing spaces
strField = trim(varString)
'Trim 2 consecutive spaces down to 1
Do While InStr(1, strField, " ")
strField = Replace(strField, " ", " ")
Loop
Dim arrWords
'split the string by spaces, this will get you the total count of the words
arrWords = split(strField, " ")
numWords = UBound(arrWords) + 1
'if the total number of words is more than you want, get the # of words you want.
if varWords < numWords then
strField = ""
for i = 0 to varWords-1
strField = strField & " " & arrWords(i)
next
end if
countWords = strField
end function




then to use it:


Code:


response.Write(countWords(field_to_use,200)) 'indicate which field you want to cut down and the number of words you want it limited to.



Was this answer helpful ? Yes No   
Guest


Are you sure this code works?



for i = 0 varWords-1 doesnt look right and this function could be really handy to us all.

Was this answer helpful ? Yes No   
Guest


should be: for i = 0 to varWords-1



corrected in above function.

Was this answer helpful ? Yes No   
Guest


Still doesnt work.



Complained of a missing do statement



I changed the "loop" to a next and it stopped falling over but didnt show the correct number of words.

Was this answer helpful ? Yes No   
Guest


that's what i get for typing to fast ... see the above, it's been corrected.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2010 by Infoqu. All rights reserved