【发布时间】:2013-10-01 07:34:55
【问题描述】:
我的代码。
string sql = "INSERT INTO TABLE1(col1, col2, col3, col4, col5) VALUES (, NULL, NULL, NULL, NULL, NULL,)";
//Insert value for the third column(between the 3rd and 4th comma)
Regex rgx = new Regex(@", null");
sql = rgx.Replace(sql, ", 'abc'", 3);// this doesn't work
sql = rgx.Replace(sql, ", 'def'", 4);// second insert
想要的结果
sql = "INSERT INTO TABLE1(col1, col2, col3, col4, col5) VALUES (, NULL, NULL, 'abc', 'def', NULL,)";
//Then I'll remove the first and last comma between the VALUES parenthesis.
【问题讨论】:
-
"//那我把第一个和最后一个逗号去掉"这是这一部分还是你的下一个问题?
-
你实际上从中得到了什么结果?乍一看,我认为您不能以这种方式使用 RegEx(尽管我对它们的了解有限)
-
@Tim 我提到了因为 SQL 语法
标签: c# string replace find-occurrences