<%'**************************************************'函数名: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.ClearEnd Function%><% str="一共有汉字" response.write str&"="&strLength(str) str1="aaa1汉字" response.write "<BR>"&str1&"="&strLength(str1) response.end %>

评论