开发者

.Net regular expression replace - prepend each word with certain character

Input "col1, col2, col3, coln"

开发者_运维知识库

Output "@col1, @col2, @col3, @coln"


Try this:

string input = "col1, col2, col3, coln";
string pattern = @"\b(\w+)\b";
string result = Regex.Replace(input, pattern, "@$1");
Console.WriteLine(result);


string input = "col1, col2, col3, coln";
string result = "@" + Regex.Replace(input, @"\s+", " @");

It depends how robust you want it to be, of course. But if it's just for SQL query parameters, which is what it appears to be, then the above should be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜