0

I am using below code to remove word "USER1". on my richtextbox1.

Is there any way to remove the word dynamically?

For example on my richtextbox1, I have below sentence and what ever user put a word inside my textbox1 "USER1". will be replaced with new input, so pleace that USER1 is holding on below sentence will be replaced with new input, so I need something to dynamically to remove the word.

How can I add my textbox1 inside below code to delete user input word dynamically?

Regex reg = new Regex("(ALTER TABLE .+ REFERENCES\\s+)\"USER1\"[.](.+)");
richTextBox1.Text = reg.Replace(richTextBox1.Text, "$1$2"); 

Before using my code sentence is below

ALTER TABLE "GRADE" ADD CONSTRAINT "GR_ENR_FK" FOREIGN KEY ("STUDENT_ID","SECTION_ID") REFERENCES "USER1"."ENROLLMENT"("STUDENT_ID","SECTION_ID") ENABLE;

After using my code my sentence will be; but USER1 is depends on the user input and it can be change.

ALTER TABLE "GRADE" ADD CONSTRAINT "GR_ENR_FK" FOREIGN KEY ("STUDENT_ID","SECTION_ID") REFERENCES "ENROLLMENT"("STUDENT_ID","SECTION_ID") ENABLE;
4

2 に答える 2

0

あなたの質問は明確ではありません

私が見る限り、あなたはこのようなものを望んでいます

Regex reg = new Regex(String.Format("(ALTER TABLE .+ REFERENCES\\s+)\"{0}\"[.](.+)",textbox1.text);
于 2013-08-21T04:42:48.203 に答える
0

これを試して:

public void RemoveWord(string word){
  Regex reg = new Regex("(ALTER TABLE .+ REFERENCES\\s+)\"" + word + "\"[.](.+)");
  richTextBox1.Text = reg.Replace(richTextBox1.Text, "$1$2"); 
}
//To remove USER1, do this
RemoveWord("USER1");
//To remove USER2, do this
RemoveWord("USER2");
于 2013-08-21T05:06:07.347 に答える