在一组字符串中找出符合要求的字符
比如:
变压器1,1层2架2排4位,Q2层4架6排7位,变压器2,变压器3,备品,15层14架26排71位,备品,组合屏AA,组合屏BB,DG1-2 就是如何确定StrText值此时为"2层3架1排5位"或者"Q2层3架1排5位"这种样子的情况,而不是其他的象"组合屏AA",或者"DG1-2" 这样之类??

解决方案 »

  1.   

    dim a as integer
    dim b as integer
    dim c as integer
    dim d as integer
    dim StrTextStrText="变压器1,1层2架2排4位,Q2层4架6排7位,变压器2,变压器3,备品,15层14架26排71位,备品,组合屏AA,组合屏BB,DG1-2"
    a=Instr(StrText,"层")
    b=Instr(StrText,"架")
    c=Instr(StrText,"排")
    d=Instr(StrText,"位")If a<>0 and b<>0 and c<>0 and d<>0 then
    msgbox "符合"
    end if
      

  2.   

    StrText的值多余了,呵呵,
    StrText="1层2架2排4位"
      

  3.   

    x = Left(StrText, a - 1)
    y = Mid(StrText, a + 1, b - a - 1)
    z = Mid(StrText, b + 1, c - b - 1)
    k = Mid(StrText, c + 1, d - c - 1)这样才行
      

  4.   

    下面的函数可完成判断
    判断mystr1中是否有mystr2对应的字符串
    例如:mystr1="11层22架33排44位"
    mystr2="层架排位"
    则函数值为true例如:mystr1="层架排位"
    mystr2="层架排位"
    则函数值为False
    Private Function FindStr(mystr1 As String, _
                             mystr2) As Boolean
    Dim i As Integer
    Dim tempNum1 As Integer
    Dim tempNum2 As Integer
    Dim tempStr As String
    FindStr = True
    For i = 1 To Len(mystr2)
        tempStr = Mid(mystr2, i, 1)
        tempNum1 = InStr(1, mystr1, tempStr)
        If tempNum2 <> tempNum1 - 1 Then
           tempNum2 = tempNum1
        Else
           FindStr = False
        End If
        If tempNum1 = 0 Then
           FindStr = False
           Exit For
        End If
    Next i
    End Function不知是否合用?合意否???