急急急急急急急急急急急急急急急!!!!!字符串模糊比较
不知道有没有方法可以判断001,002,003不是一类的,而像017A,017B,017C等等都判断是一类的,请教高人支招,谢谢!
[解决办法]
Like,支持通配符
示例:
a = "017a"
b = "016c"
If a Like "017*" Then
MsgBox "a有017前缀"
Else
MsgBox "a没有017前缀"
End If
If b Like "017*" Then
MsgBox "b有017前缀"
Else
MsgBox "b没有017前缀"
End If
Dim b As Boolean
Dim t, i As Integer
Dim s1 As String, s2 As String
For Each t In Split("001,002,003,004,005,017a,017b,018,019a,019b", ",")
b = False
For i = 1 To Len(t)
If Asc(Mid(t, i, 1)) > Asc(9) Then b = True: Exit For
Next i
If b Then s1 = s1 & " " & t Else s2 = s2 & " " & t
Next t
Dim t1, t2
t1 = Split(s1, " "): t2 = Split(s2, " ")
Private Sub Command1_Click()
Dim iStr As String, iTr() As String, i As Integer, tmp As String, tmp1 As String
iStr = "001_1,001_2,001_3,001_4,002_1,002_2,002_3,003_1,003_2,017a_1,017a_2,017a_3,017b_1,017b_2,017b_3,018_1,018_2"
iTr = Split(iStr, ",")
For i = 0 To UBound(iTr)
tmp = Mid(iTr(i), 1, InStr(iTr(i), "_") - 1)
Print tmp
tmp = IIf(Asc(Right(tmp, 1)) > 57, Left(tmp, 3), tmp)
For j = i + 1 To UBound(iTr)
tmp1 = Mid(iTr(j), 1, InStr(iTr(j), "_") - 1)
tmp1 = IIf(Asc(Right(tmp1, 1)) > 57, Left(tmp1, 3), tmp1)
If tmp <> tmp1 Then
i = j
Exit For
End If
Next
Next
End Sub