Remove all comments.

  • Thread starter Thread starter William Stacey [MVP]
  • Start date Start date
W

William Stacey [MVP]

For a given *.cs, is there a quick way to remove all "///" and "//" comment
lines? TIA.
 
Hi William,

As for the removning comment in a CS source code file you mentioned, if
we're not using the VS.NET ide, i think the only means is to define a
custom utility and programmatically load the cs file into string and parse
it, find all the comments start with "///" or "//" OR between "/* ...*/"
block.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
William,
For a given *.cs, is there a quick way to remove all "///" and "//"
comment
lines? TIA.

Whilst I have not tried it I would have thought the standard replace method
within VisualStudio would work, using the Regular Expression feature it
supports.

Phil...
 
William,

If you are not using VisualStudio you could use a text editor such as
UltraEdit which also supports Regular Expressions.

Phil...
 
I'll just type the file into find to create a file containing anything
except "//". Still good uses for dos utils I guess. Just thought VS may
have had it.
 
William,
Just thought VS may have had it.

But there is, as mentioned in my previous posting. Use Regular Expression
feature of the Replace dialog box.

Bing up the standard VS search replace dialog, select the "Use option" and
select regular expression in the combo box. Enter a regular expression
similar to "///.*$" into the find text box to find one of the variations of
comments. It should be possible to come up with an expression to handle all
types of comments.

Phil...
 
unfortunatly for me, that is problem. Every time I regex is involved, I end
up spending half the day trying to remember what I forgot and seeking the
right expression. Anyway, thanks and Cheers!
 
William,
Every time I regex is involved, I end up spending half the day trying to
remember what I forgot and seeking the right expression.

Actually you can also use the easier wild card option. Just simply enter //*
in the find box. This will replace both /// and // comments with a blank
line. But I guess this may not be suitable because it leaves a blank line
instead of removing it completly.


Phil...
 
Back
Top