Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split by crlf using VB.net

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

like image 642
user709787 Avatar asked Apr 29 '11 01:04

user709787


People also ask

What is Crlf in VB net?

Vbcrlf is a combination of the two actions explained above: the Carriage Return (VbCr) that moves the cursor back to the beginning of the line and the Line feed (VbLf) that moves the cursor position down one line. In other words, vbCrLf is to VBA what the ENTER key is to a word processor.

How do you split a string into a new line in VB?

One can only split on a char but in most cases NewLine is two characters, Carriage Return (0x0D AKA Char 13) and Line Feed (0x0A AKA Char 10). But in other systems it's just a LF. So I simply remove all instances of the CR and split on the LF.

How Split Comma Separated Values in VB net?

Split We call Split() with a Char array with 1 element—the comma char. This separates each line on the comma. RemoveEmptyEntries. Sometimes there are no characters between two delimiters.


1 Answers

Use

str.Split(ControlChars.CrLf.ToCharArray(), StringSplitOptions.RemoveEmptyEntries)

instead.

like image 151
Ry- Avatar answered Sep 21 '22 21:09

Ry-