Public Function Lench(ByVal TmpStr As String) As String Lench = LenB(StrConv(TmpStr, vbFromUnicode)) End Function
我写的函数 Function ByteLen(Str) Dim Length Length = 0 For i = 1 To Len(Str) If (Asc(Mid(Str, i, 1)) < 0) Then Length = Length + 2 Else Length = Length + 1 End If ByteLen = Length Next End Function
Function LeftByte(Str, Lens) Dim Length Length = 0 For i = 1 To Len(Str) If (Asc(Mid(Str, i, 1)) < 0) Then Length = Length + 2 Else Length = Length + 1 End If If Length = Lens Then LeftByte = Left(Str, i) Exit Function ElseIf Length > Lens Then LeftByte = Left(Str, i - 1) Exit Function End If Next End Function
Lench = LenB(StrConv(TmpStr, vbFromUnicode))
End Function
Dim Length
Length = 0
For i = 1 To Len(Str)
If (Asc(Mid(Str, i, 1)) < 0) Then
Length = Length + 2
Else
Length = Length + 1
End If
ByteLen = Length
Next
End Function
Function LeftByte(Str, Lens)
Dim Length
Length = 0
For i = 1 To Len(Str)
If (Asc(Mid(Str, i, 1)) < 0) Then
Length = Length + 2
Else
Length = Length + 1
End If
If Length = Lens Then
LeftByte = Left(Str, i)
Exit Function
ElseIf Length > Lens Then
LeftByte = Left(Str, i - 1)
Exit Function
End If
Next
End Function