tags:

views:

94

answers:

2

Input "col1, col2, col3, coln"

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

+3  A: 

Try this:

string input = "col1, col2, col3, coln";
string pattern = @"\b(\w+)\b";
string result = Regex.Replace(input, pattern, "@$1");
Console.WriteLine(result);
Ahmad Mageed
+1  A: 
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.

Dean Harding
Doesn't work for me.
MicMit
Oops, I had "\w" when it should've been "\s"
Dean Harding