c# - How can I make no line space using regex? -
i have below sentences on richtexbox1 have can make 1 line space between each line , dont make line space if sentence start create table , ends semicolomn
result:
alter table "course" drop constraint "crse_crse_fk"; alter table "enrollment" drop constraint "enr_stu_fk"; alter table "enrollment" drop constraint "enr_sect_fk"; alter table "enrollment" add constraint "enr_stu_fk" foreign key ("student_id") references "student"("student_id") enable; alter table "enrollment" add constraint "enr_sect_fk" foreign key ("section_id") references "section"("section_id") enable; create table "comp1" ( "empid" number, "emplname" varchar2(20), "empfname" varchar2(20), "deptno" number, "mgrid" number, primary key ("empid") enable ); create table "comp12" ( "empid" number, "emplname" varchar2(20), "empfname" varchar2(20), "deptno" number, "mgrid" number, primary key ("empid") enable );
expected result
alter table "course" drop constraint "crse_crse_fk"; alter table "enrollment" drop constraint "enr_stu_fk"; alter table "enrollment" drop constraint "enr_sect_fk"; alter table "enrollment" add constraint "enr_stu_fk" foreign key ("student_id") references "student"("student_id") enable; alter table "enrollment" add constraint "enr_sect_fk" foreign key ("section_id") references "section"("section_id") enable; create table "comp1" ( "empid" number, "emplname" varchar2(20), "empfname" varchar2(20), "deptno" number, "mgrid" number, primary key ("empid") enable ); create table "comp12" ( "empid" number, "emplname" varchar2(20), "empfname" varchar2(20), "deptno" number, "mgrid" number, primary key ("empid") enable );
my code (only adds 2 lines empty)
list<string> rt = new list<string>(); foreach (string line in richtexbox1 .lines) { if (line != "") { rt.add(line); rt.add(""); } } richtexbox1 .lines = rt.toarray();
just try this
private void button1_click(object sender, eventargs e) { list<string> rt = new list<string>(); foreach (string line in richtextbox1.lines) { if (!string.isnullorempty(line.trim())) { rt.add(line); } if (line.trim().endswith(";")) { rt.add("\n"); } } richtextbox1.lines = rt.toarray(); richtextbox1.refresh(); }
Comments
Post a Comment