我想知道如何在vb.net中读取和转换richtextbox的不同行 例如,如果这些是RichTextBox的行
Hello
Hi
如何将其转换为类似
的内容 Yo(Hello)
Yo(Hi)
并将结果放在第二个richtextbox中? 感谢
答案 0 :(得分:2)
RichtextBox有lines
属性:
Dim rtb_in As New RichTextBox
Dim rtb_out As New RichTextBox
For Each line In rtb_in.Lines
rtb_out.AppendText(String.Format("Foo({0})", line))
Next
最好查看MSDN以了解您使用的课程......
答案 1 :(得分:0)
您可以尝试拆分新行并修改结果:
Dim box1Lines as String() = richTextBox1.Text.Split(new String() { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
Dim newLines as String = ""
For Each line As String in box1Lines
newLines += "Yo(" & line & ")" & Environment.NewLine
Next
richTextBox2.Text = newLines
答案 2 :(得分:0)
可能你应该使用String.Join
来完成它。 one line
解决方案是:
rtbOut.Lines = ("Yo(" & String.Join(")" & Environment.NewLine & "Yo(", rtbIN.Lines) & ")").Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
以下是将修改后的行分配给第二个RichTextBox
的完整代码:
Dim rtbIN As New RichTextBox
Dim rtbOut As New RichTextBox
rtbIN.Lines = New String() {"Hello ", "Hi"}
rtbOut.Lines = ("Yo(" & String.Join(")" & Environment.NewLine & "Yo(", rtbIN.Lines) & ")").Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)