Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 918
Scott Boettger Avatar asked Dec 14 '22 03:12

Scott Boettger


2 Answers

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, ",")
like image 122
Scott Boettger Avatar answered Jan 14 '23 11:01

Scott Boettger


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, ",")
like image 34
Adam Robinson Avatar answered Jan 14 '23 12:01

Adam Robinson