True, but in the implementation for Strings.Mid, there doesn't seem to
be anything that would make its call to String.Substring any faster
than a direct call to String.Substring. I don't see how the internal
implementation of substring is relevant.
When I look at the code for String.Substring, I see this:
Public Function Substring(ByVal startIndex As Integer, ByVal length As
Integer) As String
Dim num1 As Integer = Me.Length
If (startIndex < 0) Then
Throw New ArgumentOutOfRangeException(...)
End If
If (length < 0) Then
Throw New ArgumentOutOfRangeException(...)
End If
If (startIndex > (num1 - length)) Then
Throw New ArgumentOutOfRangeException(...)
End If
Dim text1 As String = String.FastAllocateString(length)
String.FillSubstring(text1, 0, Me, startIndex, length)
Return text1
End Function
And when I look at the code for Strings.Mid I see this:
Public Shared Function Mid(ByVal str As String, ByVal Start As Integer,
ByVal Length As Integer) As String
If (Start <= 0) Then
Throw New ArgumentException(...)
End If
If (Length < 0) Then
Throw New ArgumentException(...)
End If
If ((Length = 0) OrElse (str Is Nothing)) Then
Return ""
End If
Dim num1 As Integer = str.Length
If (Start > num1) Then
Return ""
End If
If ((Start + Length) > num1) Then
Return str.Substring((Start - 1))
End If
Return str.Substring((Start - 1), Length)
End Function
Except for the few additional checks that Mid performs, it is just a
call to Substring. what would make Mid run faster? To me, it should
run slower because of the extra checks. I am still confused.