已解决,公布代码: Private Function SplitStr(LineStr As String) As String() Dim list As New List(Of String) Dim curStr As String = String.Empty Dim flag As Boolean = False For i As Integer = 0 To LineStr.Length - 1 Dim c As Char = LineStr(i) If c = Chr(34) Then If flag Then curStr += c flag = False Else If LineStr.IndexOf("""", i + 1) <> -1 Then curStr += c flag = True Else curStr += c End If End If If i = LineStr.Length - 1 Then list.Add(curStr) curStr = String.Empty End If Else If c = " " Or c = Chr(9) Or i = LineStr.Length - 1 Then If flag Then curStr += c Else If i > 0 Then If LineStr(i - 1) <> " " And LineStr(i - 1) <> Chr(9) Then If c <> " " And c <> Chr(9) Then curStr += c End If list.Add(curStr) curStr = String.Empty End If End If End If Else curStr += c End If End If Next Dim rStr(list.Count - 1) As String For i As Integer = 0 To list.Count - 1 rStr(i) = list(i) Next Return rStr End Function
Private Function SplitStr(LineStr As String) As String()
Dim list As New List(Of String)
Dim curStr As String = String.Empty
Dim flag As Boolean = False
For i As Integer = 0 To LineStr.Length - 1
Dim c As Char = LineStr(i)
If c = Chr(34) Then
If flag Then
curStr += c
flag = False
Else
If LineStr.IndexOf("""", i + 1) <> -1 Then
curStr += c
flag = True
Else
curStr += c
End If
End If
If i = LineStr.Length - 1 Then
list.Add(curStr)
curStr = String.Empty
End If
Else
If c = " " Or c = Chr(9) Or i = LineStr.Length - 1 Then
If flag Then
curStr += c
Else
If i > 0 Then
If LineStr(i - 1) <> " " And LineStr(i - 1) <> Chr(9) Then
If c <> " " And c <> Chr(9) Then
curStr += c
End If
list.Add(curStr)
curStr = String.Empty
End If
End If
End If
Else
curStr += c
End If
End If
Next
Dim rStr(list.Count - 1) As String
For i As Integer = 0 To list.Count - 1
rStr(i) = list(i)
Next
Return rStr
End Function