c#如何在RichTextBox的行值中添加字符串
本文关键字:添加 字符串 RichTextBox | 更新日期: 2023-09-27 18:07:12
namespace PostingQueueMonitoring_V2
{
public partial class Helper : Form
{
public Helper()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(input_richTextBox1.Text.Trim()))
{
MessageBox.Show("Please input text...");
return;
}
string[] myText = new string[] {input_richTextBox1.Text};
foreach (string element in myText)
{
output_richTextBox2.Text = element;
System.Console.WriteLine(output_richTextBox2.Text);
}
System.Console.WriteLine();
//output_richTextBox2.Rtf = input_richTextBox1.Rtf;
}
private void Helper_Resize(object sender, EventArgs e)
{
this.MinimumSize = new Size(736, 466);
this.MaximumSize = new Size(736, 466);
}
}
}
如何更新将格式化input_richTextBox1和output_richTextBox2中显示的文本的代码。在下面的例子。
input_richTextBox1:苹果' n班纳' n椰子' n榴梿' n橙色
output_richTextBox2的预期结果('苹果',"班纳","椰子","榴莲","橙色")
请尝试一下。
private void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(richTextBox1.Text.Trim()))
{
MessageBox.Show("Please input text...");
return;
}
var textValues = richTextBox1.Text.Split(''n').Select(txt => $"'{txt}'");
var concatValues = string.Join(",", textValues);
richTextBox2.Text = concatValues;
System.Console.WriteLine();
}