asp 的参考一下:
Function LenBLength(txt)
'★★★检测含有中文字符串的实际长度
' 调用方法同Len("STR"),如:
' Response.Write LenBLength("STR")
'═════════════════
Dim x, y, ii, tmpStr
On Error Resume Next
txt=Trim(txt)
x = Len(txt & ""): y = 0
For ii = 1 To x '如果是汉字
tmpStr = Mid(txt,ii,1)
If tmpStr <> "" Then
If Asc(tmpStr) < 0 Or Asc(tmpStr) >255 Then
y = y + 2
Else
y = y + 1
End If
End If
Next
LenBLength = y
End Function
Function LeftString(txt,length)
'★★★截取含有中文字符串指定长度
' 调用方法同Left("STR"),如:
' Response.Write LeftString("STR",10)
'════════════════
Dim x,y,ii,tmpStr
On Error Resume Next
txt=Trim(txt)
x = Len(txt & "")
y = 0
If x >= 1 Then
For ii = 1 To x '如果是汉字
tmpStr = Mid(txt,ii,1)
If tmpStr <> "" Then
If Asc(tmpStr) < 0 Or Asc(tmpStr) >255 Then
y = y + 2
Else
y = y + 1
End If
End If
If y >= length Then
txt = Left(Trim(txt),ii) '字符串限长
Exit For
End If
next
LeftString = txt
Else
LeftString = ""
End If
End Function