Assuming that
lines
is a collection of objects whose ToString formats them. (I.e., they
aren't already Strings. If the
msg
values
are Strings, then omit the .ToString() in the .AddRange().)
The only reason for the
.Split
in the
.AddRange
is if any of the
msg
objects can generate an empty string or generate multiple "lines" of text. If that is not the case, then the
.Split()
is unnecessary.
Private Shared Function ReverseComparison( _
ByVal x As String, ByVal y As String) As Integer
Return y.CompareTo(x)
End Function
Dim items As New List(Of String)()
Const CrLf As String = vbCr & vbLf
For Each msg In lines
items.AddRange(msg.ToString().Split(CrLf, StringSplitOptions.RemoveEmptyEntries))
Next
items.Sort(AddressOf ReverseComparison)
Dim sb = New StringBuilder(String.Join(CrLf, items.ToArray()))
Untested, my VB is somewhat rusty. ;-)