01-26-2003, 02: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??
01-26-2003, 04: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) & "..."
PreviewString = Left(newstr,maxlen) & "..."
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) %>
01-26-2003, 05:41 PM
thanks whammy but i designed code right now and it works.
str=" hi evrey body, i am ahmed soliman"
while spacecount=5 or i=strlen
if strtrain=" " then