怎样实现新闻标题的略写

当新闻标题的字数超过一定的数目,比如8个时,就用...代替剩余的字
像http://www.aspsky.net的下载中心下面的标题一样?
谢了先
---------------------------------------------------------------

先判断标题字符串的长度(length函数吧,好象是)
然后

if 长度大于一个数值 then
标题=left(标题,***)
else
标题=标题
end if
---------------------------------------------------------------

 1   
 2'计算标题长度,控制显示FUN_StrLen个字符   
 3'复杂点的可以加上对中文字符的判断   
 4''' --- 获得信息标题(控制字符) --- 开始 ---/   
 5Function GetInfo_Title(FUN_Title,FUN_StrLen)   
 6  
 7Dim temp_Title   
 8Dim temp_Title_Len   
 9  
10temp_Title = Trim(FUN_Title)   
11  
12IF FUN_StrLen > 0 Then   
13  
14temp_Title_Len = Len(temp_Title)   
15  
16IF temp_Title_Len > FUN_StrLen Then   
17  
18temp_Title = Left(temp_Title,FUN_StrLen)   
19temp_Title = temp_Title & "..."   
20  
21End IF   
22  
23End IF   
24  
25GetInfo_Title = temp_Title   
26  
27  
28End Function   
29''' --- 获得信息标题(控制字符) --- 结束 ---/   

:_)
---------------------------------------------------------------

还可以加一个鼠标放上去显示完整标题的功能:
title=rs("title")
id=rs("id")
if len(title)>15 then
response.write "

1<a "="" &="" href='dispnews.asp?id="' id="" title='" &amp; title &amp; "'>" &amp; left(title,15) &amp; "...</a>
1<br/>

"
else
response.write "

1<a "="" &="" href='dispnews.asp?id="' id="">" &amp; title &amp; "</a>
1<br/>

"
end if
......

Published At
Categories with Web编程
Tagged with
comments powered by Disqus