一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

asp判断字符串实际长度

时间:2010-04-14 编辑:简简单单 来源:一聚教程网

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
function strlen(str)
dim p_len,xx
p_len=0
strlen=0
if trim(str)<>"" then
p_len=len(trim(str))
for xx=1 to p_len
if asc(mid(str,xx,1))<0 then
strlen=int(strlen) + 2
else
strlen=int(strlen) + 1
end if
next
end if
end function
function cutstr(str,lennum)
dim p_num
dim i,x
if strlen(str)<=lennum then
cutstr=str
else
p_num=0
x=0
do while not p_num > lennum-2
x=x+1
if asc(mid(str,x,1))<0 then
p_num=int(p_num) + 2
else
p_num=int(p_num) + 1
end if
cutstr=left(trim(str),x)&"..."
loop
end if
end function
function InsertZero(M)
if len(M)=1 then
   InsertZero="0"&M
else
   InsertZero=M
end if
end function

热门栏目