How to remove comments from SQL string

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top