'将传入的字符串拆分为一个字符串数组返回
Public Function StrSplit(ByVal words As String) As String()
Dim split As String() = Nothing
Dim totalLen As Int64 = words.Length
Dim len As Int64 = SplitStr.Length
Dim pos As Int64
Dim i As Int16 = 1
pos = words.IndexOf(SplitStr) 'SplitStr为自定义的拆分字符串
If (pos <> -1) Then
While (pos + len) < totalLen
ReDim Preserve split(i)
split(i - 1) = words.Substring(0, pos)
words = words.Substring(pos + len)
totalLen = words.Length
pos = words.IndexOf(SplitStr)
i += 1
If (pos = -1) Then
ReDim Preserve split(i)
split(i - 1) = words
pos = totalLen
End If
End While
Else
ReDim Preserve split(1)
split(0) = words
End If
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim str As String = "insert into goat (a,b) values(1,1) go select * from goat go"
Console.WriteLine(Me.SplitSQL(str)(0)) 'insert into goat (a,b) values(1,1)
Console.WriteLine(Me.SplitSQL(str)(1)) 'select * from goat
End Sub
Private Function SplitSQL(ByVal SQL As String) As String()
If SQL.Trim.Length < 4 Then Return Nothing
Dim a As Array
Dim Last As String = SQL.Substring(SQL.Length - 3).ToLower
If Last.Equals(" go") Then SQL = SQL & " "
Return Microsoft.VisualBasic.Strings.Split(SQL, " go ", , CompareMethod.Text)
End Function