我有这个嵌套循环。我有一个名为HPArray(m)
的数组,它在字符串中有n个字符。
我如何查找000和111以及222和333(是的只有这4个三元组,它们必须是连续的)如果字符串中存在任何这些,则for循环将转到下一个m值?
For j = 2 To lenHP - 1
For k = j + 1 To lenHP
For m = 1 To cntHP
'need a condition here that looks for 000 or 333 or 222 or 111
For mM = 1 To cntLP
'most of the processing mess happens here :)
Next mM
Next m
Next k
Next j
答案 0 :(得分:1)
If (InStr(HPArray(m), "000") > 0) Or (InStr(HPArray(m), "111") > 0) Or (InStr(HPArray(m), "222") > 0) Or (InStr(HPArray(m), "333") > 0) Then
'Do something
End If
答案 1 :(得分:1)
如果您想拥有独立功能,可以使用以下功能:
Public Function ContainsTriple(ByRef in_sValue As String) As Boolean
Dim lAsciiDigit As Long
' Digit
For lAsciiDigit = 48 To 51 ' "0" to "3"
If InStr(1, in_sValue, String$(3, lAsciiDigit)) > 0 Then
ContainsTriple = True
Exit Function
End If
Next lAsciiDigit
End Function
也许我只是用它来显示String $()函数的实际用途!如果您想稍后添加其他三元组,则只需调整For循环。