从富文本框中删除单词的最佳方法是什么? [英] what is the best way to remove words from richtextbox?
本文介绍了从富文本框中删除单词的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
*强文本我有一个 RichTextBox,我喜欢搜索以 Hello Worlds 开头并包含HERE"的句子行.并以 ; 结尾半列比我喜欢只删除 "HERE". .我的句子,下面的例子只有一行句子,但句子可能有两行长,所以条件应该以Hello Worlds开头,以;结尾.半列比删除 "HERE".*
*strong textI have a richTextBox and like to search the line of sentence that starts with Hello Worlds and Contains "HERE". and end with ; semi-column than I like to delete only "HERE". . My sentence, below example is only one line of sentence, but sentence may be 2 lines long, so condition should be start with Hello Worlds and ends with ; semi-column than remove "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;
好吧,我坚持我的代码:
well I stuck on my code:
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();
这篇关于从富文本框中删除单词的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文