Contango
Contango

Reputation: 80428

Method to remove specific obsolete lines of code from an entire codebase?

I have some code:

#if SILOG
    SiAuto.Main.LogException(ex);
    // some other lines
#endif

What would be the easiest way to remove surrounding #if from my entire codebase, i.e., end up with just:

SiAuto.Main.LogException(ex);

I'm using Visual Studio 2010. I'll accept the first answer that I can test to see if it works. Looking forward to your ideas!

Upvotes: 0

Views: 92

Answers (1)

Srayer
Srayer

Reputation: 128

Assuming your codebase is all in one solution file, and you don't have nested preprocessor directives, You can do a find and replace with a regexp:

\#if SILOG{(.*\n)@}\#endif

For the replacement string, use this:

\1

Make sure have are using the "Regular expressions" find option checked.

Step by step:

  1. Open the find and replace dialog (ctrl+H)
  2. Under "Find what:", enter "#if SILOG{(.*\n)@}#endif" without the quotes
  3. Under "Replace with:", enter "\1" without the quotes
  4. Under "Look in", select "Entire Solution"
  5. Expand "Find options"
  6. Check "Use:" and select "Regular expressions" from the combobox
  7. Click "Find Next" to see if it worked
  8. Click "Replace All" if you're brave

This won't fix the indentation of the code that was between the #if / #endif, however.

Upvotes: 1

Related Questions