How to remove comments from SQL string

  • Thread starter Thread starter Andrus
  • Start date Start date
A

Andrus

I have SQL strings which contain comments starting with -- and continuing to
end of line like

string mystring=@"SELECT data, -- ending comment
-- line comment
FROM mytable
";

How to remove comment from those strings ?
I need to delete charactes starting from -- and ending with line end in
strings.
In whole line comments emty line may remain or may removed, no difference.


Andrus.
 
Andrus,

Place the string in a StringReader, and read line by line from the
string. For each line, look for two dashes. If you find it, take
everything to the left, and then add the line (without the comments) to a
StringBuilder which is being constructed without the comments.

I am curious, why are you removing the comments?
 
Back
Top