計算含有中文字符串的長度

来源:互联网 发布:什么是矩阵结构 编辑:程序博客网 时间:2024/04/27 23:02

 Public 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

'Response.Write strLength("計算含有中文字符串的長度")

原创粉丝点击