Jan 23, 2008

解決vbscript len function 無法判斷 double byte 字元


strText = ("中文123")
WScript.Echo(strText & ":" & Len(strText))
WScript.Echo(strText & ":" & newLen(strText))

Function newLen(text)
oldlen = Len(text)
newLen = 0
For i = 1 To oldlen
If Asc(Mid(text,i,1)) > 0 Then
newLen = newLen + 1
Else
newLen = newLen + 2
End If
Next
End Function

No comments: