VB.NET Rich TextBox Character Selection

I use Rich TextBox in VB.NET and pass StringBuilder. I need to replace the New Line character from the TextBox with either a space or a comma. The problem is that the standard codes for the new line do not seem to collect this new line character in this case. Is there a specific character used in Rich TextBoxes as a newline? Any help or suggestions would be appreciated.

+4
source share
5 answers

I was able to figure it out. You should use ControlChars.Lf, so the code will contain the following lines:

RichTextBox1.Text = RichTextBox1.Text.Replace(ControlChars.Lf, ",") 
+6
source

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

 RichTextBox1.Text = RichTextBox1.Text.Replace(Environment.NewLine, ",") 
+4
source

You can use the RichTextBox Lines property. Then you can insert your commas or, nevertheless, separate them as follows

 Dim sb As New StringBuilder(String.Join(",", Me.richTextBox1.Lines)) 
+1
source
 Dim linesJoined As String = String.Join(",", Me.RichTextBox1.Lines) 
+1
source

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

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

0
source

All Articles