如一個變量 strType = "<A1>212<B1:C2>222<D1,D3>"
請教怎樣將strType里面被<>包含的字符拿出來放到數組呢?
結果
astrTemp(0)="<A1>"
astrTemp(1)="<B1:C2>
astrTemp(2)="<D1,D3>"

解决方案 »

  1.   

    Option ExplicitPrivate Sub Command1_Click()
    Dim strP() As String
    Dim strT() As String
    Dim astrTemp(0 To 2) As String
    Dim strType As String
    strType = "<A1>212 <B1:C2>222 <D1,D3>"
    strP = Split(strType, "212")
    strT = Split(strP(1), "222")
    astrTemp(0) = strP(0)
    astrTemp(1) = strT(0)
    astrTemp(2) = strT(1)
    Debug.Print astrTemp(0)
    Debug.Print astrTemp(1)
    Debug.Print astrTemp(2)
    End Sub
      

  2.   

    Private Sub Form_Load()
    '引用Microsoft VBScript Regular Expressions 5.5
    Dim re As RegExp
    Dim astrTemp()
    Dim i
        Dim mh As Match
        Dim mhs As MatchCollection
        Dim strType As String
            strType = " <A1>212 <B1:C2>222 <D1,D3>"
        Set re = New RegExp
        re.Global = True
         re.Pattern = "<[\u4e00-\u9fa5\S]*>"         '同样是匹配地址,注意和上例的不同
        Set mhs = re.Execute(strType)
    For Each mh In mhs
    ReDim Preserve astrTemp(i)
    astrTemp(i) = mh
    Debug.Print astrTemp(i)
    i = i + 1
     Next
    End Sub
     
      

  3.   


        dim strType as string
        dim tmp
        dim i as long 
        strType = " <A1>212 <B1:C2>222 <D1,D3>"  
        tmp=split(trim(strType),"<")
        for i=1 to ubound(tmp)
            tmp(i)="<" & mid(tmp(i),1,instr(tmp(i),">"))
        next
        debug.? join(tmp)