【问题标题】:I need closing ) parenthesis?我需要关闭 ) 括号?
【发布时间】:2013-09-30 05:11:55
【问题描述】:

我的代码在每行末尾添加分号...但我需要在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);

【问题讨论】:

  • if((line.Trim() + ";").Length &lt;= 2) continue;
  • 我要在哪里添加这个?

标签: c# linq trim


【解决方案1】:

尝试以下操作:

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

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

【讨论】:

  • 我得到这样的结果:这是我的句子(是)这是我的句子(是)或否);这是我的句子(是)
  • 我编辑了我的问题。谢谢
  • @user2760129 代替 s.EndsWith(")"),试试 s.contains(")")
  • 你继任后我的句子变成了这样:这是我的句子(是;这是我的句子(是;或否;这是我的句子(是;这是我的句子(是;跨度>
猜你喜欢
  • 2013-03-28
  • 1970-01-01
  • 2016-11-26
  • 2014-08-09
  • 2015-09-26
  • 1970-01-01
  • 2013-01-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多