这是为两者执行的代码;你自己决定。我更喜欢string.split()。
这是您调用时执行的代码
string.split()
:
Private Function InternalSplitKeepEmptyEntries(ByVal sepList As Integer(), ByVal lengthList As Integer(), ByVal numReplaces As Integer, ByVal count As Integer) As String()
Dim startIndex As Integer = 0
Dim index As Integer = 0
count -= 1
Dim num3 As Integer = IIf((numReplaces < count), numReplaces, count)
Dim strArray As String() = New String((num3 + 1) - 1) {}
Dim i As Integer = 0
Do While ((i < num3) AndAlso (startIndex < Me.Length))
strArray(index++) = Me.Substring(startIndex, (sepList(i) - startIndex))
startIndex = (sepList(i) + IIf((lengthList Is Nothing), 1, lengthList(i)))
i += 1
Loop
If ((startIndex < Me.Length) AndAlso (num3 >= 0)) Then
strArray(index) = Me.Substring(startIndex)
Return strArray
End If
If (index = num3) Then
strArray(index) = String.Empty
End If
Return strArray
End Function
以下是调用时执行的代码
Split()函数
:
Private Shared Function SplitHelper(ByVal sSrc As String, ByVal sFind As String, ByVal cMaxSubStrings As Integer, ByVal [Compare] As Integer) As String()
Dim invariantCompareInfo As CompareInfo
Dim num2 As Integer
Dim ordinal As CompareOptions
Dim length As Integer
Dim num5 As Integer
Dim num6 As Integer
If (sFind Is Nothing) Then
length = 0
Else
length = sFind.Length
End If
If (sSrc Is Nothing) Then
num6 = 0
Else
num6 = sSrc.Length
End If
If (length = 0) Then
Return New String() { sSrc }
End If
If (num6 = 0) Then
Return New String() { sSrc }
End If
Dim num As Integer = 20
If (num > cMaxSubStrings) Then
num = cMaxSubStrings
End If
Dim strArray As String() = New String((num + 1) - 1) {}
If ([Compare] = 0) Then
ordinal = CompareOptions.Ordinal
invariantCompareInfo = Strings.m_InvariantCompareInfo
Else
invariantCompareInfo = Utils.GetCultureInfo.CompareInfo
ordinal = (CompareOptions.IgnoreWidth Or (CompareOptions.IgnoreKanaType Or CompareOptions.IgnoreCase))
End If
Do While (num5 < num6)
Dim str As String
Dim num4 As Integer = invariantCompareInfo.IndexOf(sSrc, sFind, num5, (num6 - num5), ordinal)
If ((num4 = -1) OrElse ((num2 + 1) = cMaxSubStrings)) Then
str = sSrc.Substring(num5)
If (str Is Nothing) Then
str = ""
End If
strArray(num2) = str
Exit Do
End If
str = sSrc.Substring(num5, (num4 - num5))
If (str Is Nothing) Then
str = ""
End If
strArray(num2) = str
num5 = (num4 + length)
num2 += 1
If (num2 > num) Then
num = (num + 20)
If (num > cMaxSubStrings) Then
num = (cMaxSubStrings + 1)
End If
strArray = DirectCast(Utils.CopyArray(DirectCast(strArray, Array), New String((num + 1) - 1) {}), String())
End If
strArray(num2) = ""
If (num2 = cMaxSubStrings) Then
str = sSrc.Substring(num5)
If (str Is Nothing) Then
str = ""
End If
strArray(num2) = str
Exit Do
End If
Loop
If ((num2 + 1) = strArray.Length) Then
Return strArray
End If
Return DirectCast(Utils.CopyArray(DirectCast(strArray, Array), New String((num2 + 1) - 1) {}), String())
End Function