what is the best way to remove words from richtextbox? [closed]

谁说我不能喝 提交于 2019-12-11 23:30:31

问题


*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".*

my one line of sentence:

Hello Worlds the weather is too hot "HERE"."IN" CANADA!;

my 2 lines of sentence might be this:

Hello Worlds the weather is too hot "HERE"."IN" CANADA!. But we are still like it;

result should be for one line:

 Hello Worlds the weather is too hot "IN" CANADA!;

result should be for 2 lines:

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

回答1:


you can do this

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();     


来源:https://stackoverflow.com/questions/18363308/what-is-the-best-way-to-remove-words-from-richtextbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!