Hi guys
I sincerely hope you can help. In my classic ASP page I need a function (or functions) that will do two things.
a) Firstly, strip a certain number of words from the end of a string. For example:
mystring = “the quick brown fox jumped over the lazy dog”
would display as
“the quick brown fox”
if I used something like this:
<%=mytrim(mystring, 5)%>
b) Secondly, strip a certain number of words from the beginning of a string. For example
myotherstring = “the quick brown fox jumped over the lazy dog”
would display as
“jumped over the lazy dog”
if I used something like this:
<%=myothertrim(myotherstring, 4)%>
Does this make sense? If so, is it possible and if so, how on earth is it done in classic ASP?
Any help would be fully appreciated
Best regards
Rod from the UK
PS: The closest I got was this (see below) but I couldn’t get it to work the other way:
<%
Function TrimIt(sInput, iLength)
Dim aWords, iCounter, sOutput, sTmp
sOutput = sInput
If InStr(sInput, " ") > 0 Then
aWords = Split(sInput, " ")
For iCounter = 0 To UBound(aWords)
If Len(aWords(iCounter) & " ") + Len(sTmp) <= iLength Then
sTmp = sTmp & " " & aWords(iCounter)
Else
Exit For
End If
Next
sOutput = sTmp
End If
TrimIt = sOutput + "..."
End Function
%>
<%=TrimIt(description, 150)%>