Reputation: 21
RichTextBox1.text =
1
2
3
4
5
i wounder if i can delete all lines to be 1 line length
like this
RichTextBox1.text =
12345
im using Button1
i tried
RichTextBox1.Lines.Length = 1
But its not work
Upvotes: 0
Views: 872
Reputation: 28
RichTextBox1.Lines.Length
is a number of lines in the text. Lines
is the array of all the lines, Length
is its element count.
Between each of these is an Enviroment.NewLine
character, which makes them go to a new line.
The way to do this is to remove that character manually. The simplest way is to just add the lines together as a string, and make that the new value. Put this in button 1:
Dim newLine As String = ""
For i = 0 To RichTextBox1.Lines.Length - 1
newLine = newLine & RichTextBox1.Lines(i)
Next
RichTextBox1.Text = newLine
Upvotes: 1
Reputation: 431
I've used StringBuilder to create some sample text, then I remove of new newline characters from the example with a simple replace.
StringBuilder sb = new StringBuilder();
sb.AppendLine("1");
sb.AppendLine("2");
sb.AppendLine("3");
sb.AppendLine("4");
sb.AppendLine("5");
// This is what your after
sb.ToString().Replace(Environment.NewLine,string.Empty);
Be sure to let us know how you go and welcome :D
Upvotes: 0