add a reference to Microsoft VBScript Regular Expressions 5.5, and then tryDim S As String Dim fields() As String Dim re As New RegExp Dim i As Integer Dim matches As MatchCollectionS = "select @Field1@,@Field2@,@Field3@ from +T_BaseInfo+" re.Pattern = "(@|\+)([^@+]*)\1" re.Global = True Set matches = re.Execute(S) ReDim fields(matches.Count - 1) For i = 0 To matches.Count - 1 fields(i) = matches(i).SubMatches(1) NextMsgBox Join(fields, Chr(13) & Chr(10))
"Select " & Field1 &"," & Field2 & "," & Field3 & " From " & T_BaseInfo
e.g,
Dim strTemp() As String
strTemp = Split("a,b,c", ",", , vbTextCompare)
Debug.Print strTemp(0) 'a
Debug.Print strTemp(1) 'b
Debug.Print strTemp(2) 'c
Dim fields() As String
Dim re As New RegExp
Dim i As Integer
Dim matches As MatchCollectionS = "select @Field1@,@Field2@,@Field3@ from +T_BaseInfo+"
re.Pattern = "(@|\+)([^@+]*)\1"
re.Global = True
Set matches = re.Execute(S)
ReDim fields(matches.Count - 1)
For i = 0 To matches.Count - 1
fields(i) = matches(i).SubMatches(1)
NextMsgBox Join(fields, Chr(13) & Chr(10))