2013-08-21 149 views
0

* 強大的文本我有一個RichTextBox,喜歡尋找一句話,與世界你好開始,蘊含「這裏的」行。並結束於;半列比我喜歡只刪除「HERE」。 。我的句子,下面的例子只是句子的一行,而句子可能是2行,所以條件應該以Hello Worlds開頭並以;半列比刪除 「這裏」 *從richtextbox中移除單詞的最佳方式是什麼?

我的一句話的行:

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

回答

1

你可以做到這一點

在(「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();  
+0

錯誤無法從「字符串」到「廉政」轉換。它看起來像string.Remove(int) – user2661591

+0

我喜歡刪除「HERE」。 – user2661591

+0

更新........ – Ehsan

相關問題