0

*强文本我有一个richTextBox,喜欢搜索以Hello Worlds 开头并包含“HERE”的句子行。并以 ; 结尾 半栏比我喜欢只删除“这里”。 . 我的句子,下面的例子只有一行句子,但句子可能有 2 行长,所以条件应该以 Hello Worlds 开头并以 ; 结尾 半列而不是删除“这里”。*

我的一句话:

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".
                            }
                        }
4

1 回答 1

1

你可以这样做

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();     
于 2013-08-21T16:55:18.010 回答