有sql 语句 大致是下面这样select * from tablea where name like %s select * from tablea where id = s %s 和 s 是 参数,要替换成:张三select * from tablea where name like '%张三' select * from tablea where id = '张三' 
 

解决方案 »

  1.   

    没有细致完善,条件是 s后面没有单词字符匹配            //string s = "select * from tablea where name like %s  ";
                string s = "select * from tablea where id = s  ";
                Regex reg = new Regex(@"s[\W]");
                s = reg.Replace(s, "张三");
      

  2.   

    try...            string test = @"select * from tablea where name like %s  select * from tablea where id = s  ";
                Regex reg = new Regex(@"(%?)\bs\b");
                string result = reg.Replace(test, "'$1张三'");
                richTextBox2.Text = result;