code formatting: how to clean unnecessary blank lines?

  • Thread starter Thread starter Andreas Bauer
  • Start date Start date
A

Andreas Bauer

Hi,

I have to audit some c# code. I know in the options I can adjust how
the code should be formatted while entering it. But is there any way to
apply afterwards a code template to the classes to adjust their
appearance (except ctrl-k ctrl-f)? Foremost how to clear unnecessary
blank lines, e.g reduce 4 blank lines to one. I don´t want to change
every class manually.

Thanks in advance for any hint.

Regards, Andreas
 
Hi Andreas,

I'm not sure what other formatting you want to do, but if you mainly
want to clear blank lines, you can do this easily by using regular
expressions, either within the IDE or using a command-line tool. Using
your example below, you could replace 4 blank lines with 1 blank line
by searching for "\n\n\n\n\n" and replacing it with "\n\n". You can do
something similar in a command-line batch file using a tool like SED.

Hope this helps,
John
 
Hello!

Remove unnecessary blank links using RegEx with the standard search /
replace dialog.

I'd also suggest using CTRL+K / CTRL+D (if using a standard VS 2005 layout)
to clean the source code (works for most languages). It automatically
formats your selection / document to your current configuration preferences.
If you're using a different layout, choose Edit / Advances / Format
Document.
 
Hi,

thanks for the hints. What I´m actually looking for is something like
the functions existing in eclipse. There you can specify how many blank
lines, where to break the line, where to put the brackets. Except blank
lines, I found everything within the configuration. But want to
eliminate all unnecessary blank lines (3,4 or 5) to one.
Is this possible too?

Thanks,

regards,

Andreas
 
Hi!

I haven't seen a generic built-in method in VS 2005 that allows you to
"clean up" the code by removing unnecessary blank lines, but it could be
accomplished with a macro. It's actually a good request for the next version
of VS 2005 (codename "orcas" scheduled for release by end 2007 am I not
mistaken).

AFAIK the macro or search/replace with regex is your best bets right now.
Could be that there is an add-in out there on the web that allows such
operations.
 

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

Back
Top