RichTextBox1.text =
1
2
3
4
5如果我能删除所有行的长度为1行,我会感到惊讶。
像这样
RichTextBox1.text =
12345我在使用Button1
我试过了
RichTextBox1.Lines.Length = 1但它不起作用
发布于 2018-09-18 22:34:07
RichTextBox1.Lines.Length是文本中的许多行。Lines是所有行的数组,Length是它的元素计数。
每个字符之间都有一个Enviroment.NewLine字符,这使得它们转到了一个新行。
这样做的方法是手动删除该字符。最简单的方法是将这些行相加为一个字符串,并使其成为新的值。把这个放在按钮1中:
Dim newLine As String = ""
For i = 0 To RichTextBox1.Lines.Length - 1
newLine = newLine & RichTextBox1.Lines(i)
Next
RichTextBox1.Text = newLine发布于 2018-09-18 22:40:58
我使用StringBuilder创建了一些示例文本,然后用简单的替换从示例中删除新的换行符。
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);一定要让我们知道你是怎么走的,欢迎:
https://stackoverflow.com/questions/52395193
复制相似问题