如何取得字符串中字符长度

来源:互联网 发布:新加坡网上购物软件 编辑:程序博客网 时间:2024/05/16 16:12
Function LengthOfString(str)
Dim l,c,i,t
LengthOfString 
= 0
If str="" Then Exit Function
l
=Len(str)
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
Next
LengthOfString 
= t
End Function

dim a,b
a
="admin"
b
="中国"

Response.Write LengthOfString(a) 
'输出:5
Response.Write("<br>")
Response.Write LengthOfString(b) 
'输出:4