Need help how to proper split a string by crlf
below is the code:
Dim str As String = "Hello" & vbCrLf & "World"
Dim parts As String() = str.Split(ControlChars.CrLf.ToCharArray)
For Each part As String In parts
MsgBox(part)
Next
Output
Hello
World
I want to get rid the blank space in between the two.
Hello
World
If you want to support all kinds of newlines (CR, LF, CR LF) and don’t need blank lines, you can split on both characters and make use of the
String.Splitoption that stops it from producing empty entries:(This also produces an empty array if the input is empty.)
If you know you have consistent CR LF newlines and you want to preserve blank lines, you can split on the entire delimiter: