Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net RichTextBox行长度=1_.net_Vb.net_Visual Studio_Richtextbox - Fatal编程技术网

.net RichTextBox行长度=1

.net RichTextBox行长度=1,.net,vb.net,visual-studio,richtextbox,.net,Vb.net,Visual Studio,Richtextbox,RichTextBox1.text= 如果我能将所有行删除为1行长度,我会很伤心 像这样 RichTextBox1.text= 我在用按钮1 我试过了 RichTextBox1.Lines.Length = 1 但是它不起作用RichTextBox1.Lines.Length是文本中的许多行行是所有行的数组,长度是其元素计数 在每一个字符之间都有一个Environment.NewLine字符,使它们转到新行 方法是手动删除该字符。最简单的方法是将行作为字符串添加在一起,并使其成为新值。把这

RichTextBox1.text=

如果我能将所有行删除为1行长度,我会很伤心

像这样

RichTextBox1.text=

我在用按钮1

我试过了

  RichTextBox1.Lines.Length = 1

但是它不起作用

RichTextBox1.Lines.Length
是文本中的许多行<代码>行是所有行的数组,
长度
是其元素计数

在每一个字符之间都有一个
Environment.NewLine
字符,使它们转到新行

方法是手动删除该字符。最简单的方法是将行作为字符串添加在一起,并使其成为新值。把这个放在按钮1:

Dim newLine As String = ""
For i = 0 To RichTextBox1.Lines.Length - 1
    newLine = newLine & RichTextBox1.Lines(i)
Next
RichTextBox1.Text = newLine

我使用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);

请务必让我们知道您的进展情况,并欢迎:D

非常感谢您的工作,但这里是您的一个小编辑,RichTextBox1.Text=TextBox1.Text.Replace(“,”)Dim newLine As String=“”,用于i=0到RichTextBox1.Lines.Length-1 newLine=newLine&RichTextBox1.Lines(i)下一个RichTextBox1.Text=newLine@Beginner01您也可以在一行中完成此操作:
RichTextBox1.Text=String.Join(String.Empty,RichTextBox1.Lines)
Ohh,我没有使用C#,但我可以猜它也可以工作,Big-ty需要您的帮助,它已经解决了,Big-ty。啊,我的坏朋友没有看到Vb.net标记。从记忆上看几乎是一样的。不,这是我的错,因为我标记了general viual basic。再次感谢您的帮助。请使用
sb.Append
而不是
sb.AppendLine
以避免使用替换函数。@LarsTech,嘿,伙计,如果您是正确的,我只使用AppendLine复制了手头的示例。
Dim newLine As String = ""
For i = 0 To RichTextBox1.Lines.Length - 1
    newLine = newLine & RichTextBox1.Lines(i)
Next
RichTextBox1.Text = newLine
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);