定义一数组
Dim item(10) As String
item(0) = "AA"
item(1) = "BB"
item(2) = "CC"
item(3) = "DD"
item(4) = "EE"
......有一个字符串 str ,怎么判断他是否是数组里面所包含的? 有类似于c#的 contains方法么?
Dim item(10) As String
item(0) = "AA"
item(1) = "BB"
item(2) = "CC"
item(3) = "DD"
item(4) = "EE"
......有一个字符串 str ,怎么判断他是否是数组里面所包含的? 有类似于c#的 contains方法么?
Dim item(10) As String
Dim str As String
str = "DD"
item(0) = "AA"
item(1) = "BB"
item(2) = "CC"
item(3) = "DD"
item(4) = "EE"
If InStr(1, Join(item, ","), str) > 0 Then MsgBox "have"End Sub
Private Sub Command1_Click()
Dim a As New Collection
a.Add "aa", "aa"
a.Add "bb", "bb"
a.Add "dd", "dd"
a.Add "ee", "ee"
a.Add "ff", "ff"Debug.Print FindInCol(a, "dd")
Debug.Print FindInCol(a, "zz")
End Sub
Private Function FindInCol(col As Collection, strFind As String) As Boolean
On Error GoTo ErrHandle
Dim a As Variant
FindInCol = True
a = col(strFind)
Exit Function
ErrHandle:
FindInCol = False
End Function
Private Sub Command1_Click()
Dim item(10) As String
Dim str As String
str = "BC"
item(0) = "AB"
item(1) = "CD"
item(2) = "EF"
item(3) = "GH"
item(4) = "IJ"
'HAVE提示的时候,其实是没有的。
If InStr(1, Join(item, ","), str) > 0 Then MsgBox "have"End Sub
Dim item(10) As String
Dim str As String
Dim i
str = "DD"
item(0) = "AA"
item(1) = "BB"
item(2) = "CC"
item(3) = "DD"
item(4) = "EE"
For i = 0 To 10
If item(i) = str Then MsgBox "有" & str
Next
End Sub