欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何將長的標(biāo)題用省略號收尾

 更新時間:2007年02月09日 00:00:00   作者:  
從數(shù)據(jù)庫中提取長長的文章,總是有礙網(wǎng)頁的排版布局。

所以,想固定地提取一部分字符,然后后面有……替代。

1,原理:
判斷文章的長度是否超過規(guī)定的長度,若超過則只顯示規(guī)定長度的大學(xué),否則完整顯示。

2,涉及函數(shù):

len():返回字符串長度或者變量的字節(jié)長度。

left():截取一個字符串的前部分

3,主要程序:判斷內(nèi)容長度是否大于給定值,據(jù)結(jié)果做相應(yīng)操作

4,ASP中應(yīng)用
以上是在客戶端腳本調(diào)試,和ASP也是大同小異:最主要的是函數(shù)功能。


<%
text=rs("content")  '將數(shù)據(jù)庫字段值賦到某變量上
i=10                      '定義固定大小
if len(text)>i then   '如果文本長度大于給定的值
text=left(text,i)     '則提取前段的i位的字符串
response.write (text&"...")
else
response.write (text)
end if
%>


5,為了方便,做成函數(shù)


<%
function conleft(content,i)
if len(content)>i then  
content=left(content,i)    
response.write (content&"...")
else
response.write (content)
end if
end function
%>


以上為函數(shù),下面就可以直接調(diào)用。


<%call conleft(rs("content"),10)%>


OK,相信以后遇到這些問題應(yīng)該是NO PROBLEM 

為了解決中英文截取的問題,建議大家使用如下函數(shù):


Function gotTopic(str,strlen)
    if str="" then
        gotTopic=""
        exit function
    end if
    dim l,t,c, i
    str=replace(replace(replace(replace(str,"&nbsp;"," "),"&quot;",chr(34)),"&gt;",">"),"&lt;","<")
    l=len(str)
    t=0
    for i=1 to l
        c=Abs(Asc(Mid(str,i,1)))
        if c>255 then
            t=t+2
        else
            t=t+1
        end if
        if t>=strlen then
            gotTopic=left(str,i) & "…"
            exit for
        else
            gotTopic=str
        end if
    next
    gotTopic=replace(replace(replace(replace(gotTopic," ","&nbsp;"),chr(34),"&quot;"),">","&gt;"),"<","&lt;")
End Function

相關(guān)文章

最新評論