ASP过长标题如何截断

在冰灼小憩我找到一篇文章~但放到程序里无效~应该如何~请教教小弟`~
以下是文单内容:
    在文章列表的时候,如果标题过长,往往会撑破表格破坏页面形象。一般做法是略去超长部分而以省略号代替。比如要取前10个字符,则可写出以下语句:
    
    if Len(title)>10 then title=Left(title,9)+"…"  
        '凑起来刚好10个字符
    
    而我们中国人要面对现实——汉字宽度是字母的两倍。所以得设计一个函数,用一个变量计算字符串长度,如果遇到的是字母,这个长度就加1,如果遇到的是汉字,长度加2:
    
    FUNCTION cuttitle(str,strlen)
        'str为待切标题,strlen为截取长度(按字母计算)
        dim tmplen,tmpstr,i,s
        tmpstr=""
        tmplen=0
        str=trim(str)
        if str="" then exit function
        for i=1 to Len(str)
            s=mid(str,i,1)
            tmpstr=tmpstr&s
            tmplen=tmplen+1
            if Asc(s)<0 then tmplen=tmplen+1
            '如果是汉字,长度再加1
            if tmplen>strlen then
                tmpstr=Left(tmpstr,Len(tmpstr)-2)&"…"
                exit for
            end if
        next
        cuttitle=tmpstr
    END FUNCTION 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值