Scott Boettger
Scott Boettger

Reputation: 3667

VB.NET Rich TextBox Newline Character removal

I am using a Rich TextBox in VB.NET and passing to a StringBuilder. I need to replace the New Line character from the TextBox with either a space or a comma. Problem is the standard codes for new line don't seem to be picking up this New Line character in this case. Is there a specific character used in Rich TextBoxes as the New Line? Any help or suggestions will be appreciated.

Upvotes: 4

Views: 13310

Answers (5)

Scott Boettger
Scott Boettger

Reputation: 3667

I was able to figure it out. You have to use ControlChars.Lf so the code would be along the lines of the following:

RichTextBox1.Text = RichTextBox1.Text.Replace(ControlChars.Lf, ",")

Upvotes: 6

Adam Robinson
Adam Robinson

Reputation: 185643

You can try Environment.NewLine as a language-agnostic constant for a true newline (you should try to avoid language-specific constants and functions when possible).

RichTextBox1.Text = RichTextBox1.Text.Replace(Environment.NewLine, ",")

Upvotes: 4

Dan Tao
Dan Tao

Reputation: 128317

Dim linesJoined As String = String.Join(",", Me.RichTextBox1.Lines)

Upvotes: 1

JHBlues76
JHBlues76

Reputation: 21

You could use the RichTextBox's Lines property. You could then insert your commas or however you're delimiting it as follows

Dim sb As New StringBuilder(String.Join(",", Me.richTextBox1.Lines))

Upvotes: 1

Anders
Anders

Reputation: 12560

Sometimes it is just chr(10) or chr(13). VbCrLf is a combination of both chr(10) and chr(13).

Try parsing out one or the other, and see if that helps.

Upvotes: 0

Related Questions