我需要关闭)括号?

时间:2013-09-30 05:11:55

标签: c# linq trim

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

NOT:我的第二句话可以以任何单词结束,这意味着继承s.Endwith(“no”)替换(“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);

1 个答案:

答案 0 :(得分: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(";")

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