从richtextbox中删除单词的最佳方式是什么
本文关键字:最佳 方式 是什么 单词 richtextbox 删除 | 更新日期: 2023-09-27 18:28:27
*strongtext我有一个richTextBox,喜欢搜索以Hello Worlds开头并包含"HERE"的句子行。并以结尾;半列,我只想删除"HERE"。我的句子,下面的例子只有一行,但句子可能有两行长,所以条件应该以Hello Worlds开头,以结尾;半列删除"HERE"。*
我的一行话:
Hello Worlds the weather is too hot "HERE"."IN" CANADA!;
我的两行句子可能是这样的:
Hello Worlds the weather is too hot "HERE"."IN" CANADA!. But we are still like it;
结果应该是一行:
Hello Worlds the weather is too hot "IN" CANADA!;
结果应为2行:
Hello Worlds the weather is too hot "IN" CANADA!. But we are still like it;
我坚持我的代码:
List<string> rt = new List<string>();
foreach (string line in richTextBox1.Lines)
{
if (line.StartsWith("Hello Worlds") && line.Contains("HERE"))
{
//remove "HERE".
}
}
您可以执行此
string[] lines = richTextBox1.Lines;
List<string> linesToAdd = new List<string>();
string filterString = "'"HERE'".";
foreach (string s in lines)
{
string temp = s;
if (s.StartsWith("Hello Worlds") && s.EndsWith(";") && s.Contains(filterString))
temp = s.Replace(filterString, string.Empty);
linesToAdd.Add(temp);
}
richTextBox1.Lines = linesToAdd.ToArray();