' ============================================
' 截取源字符串Str的前LenNum个字符(一个中文字符为2个字节长)
' ============================================
Public Function CutStr(Str, LenNum, ViewType)
Dim P_Num
Dim I, X
If StrLen(Str) <= LenNum Then
CutStr = Str
Else
P_Num = 0
X = 0
Do While Not P_Num > LenNum - 2
X = X + 1
If Asc(Mid(Str, X, 1)) < 0 Then
P_Num = Int(P_Num) + 2
Else
P_Num = Int(P_Num) + 1
End If
CutStr = Left(Trim(Str), X) & ViewType
Loop
End If
End Function
' ============================================
'检测字符串的类型
'返回 0-空
'返回 1-数字
'返回 2-英文
'返回 3-汉字
'返回 4-英汉
'返回 5-英数
'返回 6-汉数
'返回 7-全
'============================================
Public Function StrType(Str)
On Error Resume Next
Dim I, A, E, N, C
E = False : N = False : C = False
If IsNull(Str) Then StrType = 0 : Exit Function
If Trim(Str) = "" Then StrType = 0 : Exit Function
For I = 1 To Len(Str)
A = Asc(Mid(Str, I, 1))
If A >= 48 And A <= 57 Then N=True
If ( A >= 65 And A <= 90 ) Or ( A >= 97 And A <= 122 ) Or ( A>= 38 And A <= 39 ) Then E = True
If A < 0 Then C = True
Next
If N And (Not E) And (Not C) Then
StrType = 1
Elseif E And (Not N) And (Not C) Then
StrType = 2
Elseif C And (Not E) And (Not N) Then
StrType = 3
Elseif C And E And (Not N) Then
StrType = 4
Elseif N And E And (Not C) Then
StrType = 5
Elseif C And N And (Not E) Then
StrType = 6
Elseif N And E And C Then
StrType = 7
Else
StrType = 0
End If
If Err Then Err.Clear
End Function