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.
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, ",")
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).
Environment.NewLine
RichTextBox1.Text = RichTextBox1.Text.Replace(Environment.NewLine, ",")
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))
Dim linesJoined As String = String.Join(",", Me.RichTextBox1.Lines)
Sometimes it's just chr(10) or chr(13) . VbCrLf is a combination of both chr(10) and chr(13) .
chr(10)
chr(13)
VbCrLf
Try to make out one or the other, and see if that helps.