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.
精彩评论