I find that a pretty reliable way to read the lines of a string is to use a StringReader
:
Dim strList As New List(Of String)
Using reader As New StringReader(Clipboard.GetText())
While reader.Peek() <> -1
strList.Add(reader.ReadLine())
End While
End Using
Maybe that's weird; I don't know. It's nice, though, because it frees you from dealing with the different ways of representing line breaks between different systems (or between different files on the same system).
Taking this one step further, it seems you could do yourself a favor and wrap this functionality in a reusable extension method:
Public Module StringExtensions
<Extension()> _
Public Function ReadAllLines(ByVal source As String) As IList(Of String)
If source Is Nothing Then
Return Nothing
End If
Dim lines As New List(Of String)
Using reader As New StringReader(source)
While reader.Peek() <> -1
lines.Add(reader.ReadLine())
End While
End Using
Return lines.AsReadOnly()
End Function
End Module
Then your code to read the lines from the clipboard would just look like this:
Dim clipboardContents As IList(Of String) = Clipboard.GetText().ReadAllLines()