0

我的代码在每行的末尾添加分号......但我需要在richtextbox1 上的第二句话中关闭)括号。如何正确添加?

NOT:我的第二句话可以以任何单词结尾,这意味着继承 s.Endwith("no") replace ("no",");")..... 不是使用选项!。

我的代码只放 ; 每行的结尾

string[] lines = richTextBox1.Lines;
List<string> ToAdd = new List<string>();

string filter = ")";

foreach (string s in lines)
{
string hold = s;
if (s.EndsWith(")"))
hold = s.Replace(filter, ";");
}
richTextBox1.Lines = ToAdd.ToArray();

我的结果

This is my sentence (Yes);
This is my sentence (Yes) or no; 
This is my sentence (Yes);
This is my sentence (Yes);

我想要这个结果:

This is my sentence (Yes);
This is my sentence (Yes) or no);
This is my sentence (Yes);
This is my sentence (Yes);
4

1 回答 1

0

尝试以下操作:

    OracleDataReader reader = Command.ExecuteReader())
    {
     reader.Read();

    string[] split = reader[0].ToString().Trim().Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

     foreach (string line in split)
    {
     if(line.Trim()==")")
    richTextBox1.AppendText(line.Trim() + ";" + Environment.NewLine);
     else
  richTextBox1.AppendText(line.Trim() + Environment.NewLine);
    }  
    }

编辑:

在 for 循环之前,请尝试以下操作:

if(reader[0].toString()==")")
reader[0].append(";")

(不完全一样,但可以继续这个逻辑)

于 2013-09-30T05:54:09.600 回答