设为首页 | 加入收藏 | 
ASP获取字符串长度/截取字符串,汉字一个算两个字符,英文算一个字符
作者:佚名 时间:12月27日 来源:互联网 浏览次数:【字号: 】 

第一个函数:

'**************************************************
'函数名:strLength
'作 用:求字符串长度。汉字算两个字符,英文算一个字符。
'参 数:str ----要求长度的字符串
'返回值:字符串长度
'**************************************************

function strLength(str)
 ON ERROR RESUME NEXT
 dim WINNT_CHINESE
 WINNT_CHINESE    = (len("中国")=2)
 if WINNT_CHINESE then
        dim l,t,c
        dim i
        l=len(str)
        t=l
        for i=1 to l
         c=asc(mid(str,i,1))
            if c<0 then c=c+65536
            if c>255 then
                t=t+1
            end if
        next
        strLength=t
    else
        strLength=len(str)
    end if
    if err.number<>0 then err.clear
end function

第二个函数:

'*************************************************
'函数名:gotTopic
'作 用:截字符串,汉字一个算两个字符,英文算一个字符
'参 数:str ----原字符串 strlen ----截取长度
'返回值:截取后的字符串
'*************************************************
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

 * 以上任何内容或信息侵犯了你的利益,请及时联系!
泡泡搜索
最新文章
热点文章
精彩推荐
 - TOP