如EXCEL上表格内容4 XF 26 &CJ2&KA1&VRG&4AA/4AW/4FA-KU1/KU3 表示的是4 XF 26并且包含CJ2并且包含KA1并且包含VRG并且包含4AA并且包含4FA但是不包含KU1不包含KU3,VBA中是否有方法可以解析,这种字符串加逻辑字符?求助?例如A&B&C-D/E  那么我判断A为真,B为真,C为真,not D为真,not E为真 那么我这个就为真
而判断A,B,C,D,E是在另一张表上,这个东西是否包含A,包含就是真

解决方案 »

  1.   

    可以试试调用VBScript的Eval函数。
      

  2.   

    仅供参考:Function RegExpN(ptn, txt, n) As String
    'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 1) + "]"
    '[22220101]
    'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 2) + "]"
    '[11000011]
    'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 3) + "]"
    '[00111100]
    'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 4) + "]"
    '[10101010]
    'Debug.Print "[" + RegExpN("[012]{8}", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 5) + "]"
    '[]
    'Debug.Print "[" + RegExpN("[a-z]+(\d+)[_.]", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 4) + "]"
    '[xor10101010.]
    'Debug.Print "[" + RegExpN("[a-z]+(\d+)[_.]", "mno_if22220101_and11000011_or00111100_xor10101010.txt", 4.1) + "]"
    '[10101010]
    'Debug.Print "[" + RegExpN("<abc>(.*)</abc>", "<html><ab>AB</ab><abc>ABC汉字</abc></html>", 1) + "]"
    '[<abc>ABC汉字</abc>]
    'Debug.Print "[" + RegExpN("<abc>(.*)</abc>", "<html><ab>AB</ab><abc>ABC汉字</abc></html>", 1.1) + "]"
    '[ABC汉字]
    Dim rtnstr As String
    Dim codestr As String
        rtnstr = ""
        With ScriptControl1
            ' Set script language (VBScript is the default).
            .Language = "VBScript"
            ' Set UI interaction (TRUE is the default).
            .AllowUI = True
            ' Copy the script to the control.
    '--------------------------------------------------------
    codestr = ""
    codestr = codestr + "Function RegExpTest(patrn, strng, ns)      " + vbCrLf
    codestr = codestr + "    Dim regEx, Match, Matches, RetStr, ii  " + vbCrLf
    codestr = codestr + "    Dim nn,ss                              " + vbCrLf
    codestr = codestr + "    nn=fix(ns)                             " + vbCrLf
    codestr = codestr + "    if nn=ns then                          " + vbCrLf
    codestr = codestr + "        ss=-1                              " + vbCrLf
    codestr = codestr + "    else                                   " + vbCrLf
    codestr = codestr + "        ss=(ns-nn)*10-1                    " + vbCrLf
    codestr = codestr + "    end if                                 " + vbCrLf
    codestr = codestr + "    Set regEx = New RegExp                 " + vbCrLf
    codestr = codestr + "    regEx.Pattern    = patrn               " + vbCrLf
    codestr = codestr + "    regEx.IgnoreCase = True                " + vbCrLf
    codestr = codestr + "    regEx.Global     = True                " + vbCrLf
    codestr = codestr + "    Set Matches = regEx.Execute(strng)     " + vbCrLf
    codestr = codestr + "    ii=0                                   " + vbCrLf
    codestr = codestr + "    For Each Match in Matches              " + vbCrLf
    codestr = codestr + "        ii=ii+1                            " + vbCrLf
    codestr = codestr + "        if ii=nn then                      " + vbCrLf
    codestr = codestr + "            if ss=-1 then                  " + vbCrLf
    codestr = codestr + "                RetStr=Match.Value         " + vbCrLf
    codestr = codestr + "            else                           " + vbCrLf
    codestr = codestr + "                RetStr=Match.SubMatches(ss)" + vbCrLf
    codestr = codestr + "            end if                         " + vbCrLf
    codestr = codestr + "            exit for                       " + vbCrLf
    codestr = codestr + "        end if                             " + vbCrLf
    codestr = codestr + "    Next                                   " + vbCrLf
    codestr = codestr + "    RegExpTest = RetStr                    " + vbCrLf
    codestr = codestr + "    Set regEx = Nothing                    " + vbCrLf
    codestr = codestr + "End Function                               " + vbCrLf
    '--------------------------------------------------------
            .AddCode codestr
            Dim oMod As Object
            Set oMod = .Modules(GlobalModule)
            rtnstr = oMod.Run("RegExpTest", ptn, txt, n)
            Set oMod = Nothing
        End With
        RegExpN = rtnstr
    End Function