如何从RichTextBox添加分号并删除换行符?

时间:2013-07-24 17:16:15

标签: c#

*我有一个富文本框,并且我在文本*

下面的richtextbox上

*的结果:

  ALTER TABLE "TBL_A" ADD ("FIELD_A6" NUMBER(2,0) NOT NULL ENABLE)

  ALTER TABLE "TBL_A" DROP ("FIELD_A3")

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A2" VARCHAR2(20))

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A4" NUMBER(5,2))

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A4" NOT NULL ENABLE)

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A5" NULL)

有什么方法可以获得一个换行符的结果,每行也用分号结尾?:

预期结果:

  ALTER TABLE "TBL_A" ADD ("FIELD_A6" NUMBER(2,0) NOT NULL ENABLE);

  ALTER TABLE "TBL_A" DROP ("FIELD_A3");

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A2" VARCHAR2(20));

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A4" NUMBER(5,2));

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A4" NOT NULL ENABLE);

  ALTER TABLE "TBL_A" MODIFY ("FIELD_A5" NULL);

1 个答案:

答案 0 :(得分:1)

这是方法:

string text = richTextBox1.Text;
richTextBox1.Text = "";

string[] splitted = text.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

foreach (string line in splitted)
{
    richTextBox1.AppendText(Environment.NewLine + line.Trim() + ";" + Environment.NewLine);
}