...

View Full Version : Thread Demo



ahmedsoliman
01-26-2003, 01:56 PM
if i design forum site and need the user to link to new threads by it's demo not the title, i have to take 5 words from the newest thread then link it to the complete thread, for example my thread will be like this:

if idesign forum site... (http://www.codingforums.com/showthread.php?s=&threadid=13650)

i think i have to coonvert string to array thin count spaces then cut and print the result but how by the code??

whammy
01-26-2003, 03:52 PM
Instead of going by number of words, if you don't want your table to get out of whack assuming someone might type in a bunch of letters in a row, I'd use something like this:



<%
Function PreviewString(byVal str)
Dim strarray, joinLen, psRegEx, newstr, maxlen, spaceexists
' Change the maxlength (maxlen) below into something more feasible, this is for example.
maxlen = 50
Set psRegEx = New RegExp
psRegEx.Pattern = "\s+"
psRegEx.Global = True
newstr = Join(Split(psRegEx.Replace(Trim(Replace(str,vbCrLf," "))," ")," ")," ")
spaceexists = (InStrRev(newstr," ",maxlen)-1 > -1)
If spaceexists = True Then
PreviewString = Left(newstr,InStrRev(newstr," ",maxlen)-1) & "..."
Else
PreviewString = Left(newstr,maxlen) & "..."
End If
End Function

MyString = "This is a test of the Emergency Broadcast System. The broadcasters of your area in voluntary cooperation with the Federal, State and local authorities have developed this system to keep you informed in the event of an emergency. If this had been an actual emergency, (optional -- stations may mention the types of emergencies likely to occur in their area) the Attention Signal you just heard would have been followed by official information, news or instructions. This station (optional -- insert station call sign) serves the (operational area name) area. This concludes this test of the Emergency Broadcast System."
MyBadString = "ZZZZZZZZZZZZZZzzzzzzzzzzzzzzzzzzzzzzzzzzZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZzzzzzzzzzZZZZZZZZZZZZZZZZZ ZZZZZZZZZZZZZZ"
%>

<% = PreviewString(MyString) %><br />
<% = PreviewString(MyBadString) %>

ahmedsoliman
01-26-2003, 04:41 PM
thanks whammy but i designed code right now and it works.
<%
str=" hi evrey body, i am ahmed soliman"
strlen=len(str)

while spacecount=5 or i=strlen
i=i+1

strtrain=mid(str,i,1)
demotext=demotext&strtrain
if strtrain=" " then
spacecount=spacecount+1
end if

wend
dot="..."
demotext=demotext&dot
Response.Write(demotext)
Response.Write("<br>")

%>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum