Visual Studio deletes all the pure comments and blank lines in the source code with search replacement

Source: Internet
Author: User

Original http://www.cnblogs.com/bitzhuwei/archive/2013/04/10/remove_all_pure_notes.html

Visual Studio is deleted with search replacement.Source codeAll // methods in pure comments and empty rows

Note: XML annotations including // <summary> are also deleted.

Step 1/2 (Delete comment): Use the CTRL + H quick replacement function to find the following content:

 
^ [\ T] * // [^ \ n] * \ n

ReplaceNull(Do not write anything), you can set the search range (I like to selectEntire Solution). Select the search option.Use Regular Expressions. Then clickReplace allThat's all.

This will delete the comments of the original line/And leave no blank lines.

Step 2/2 (delete empty rows): then set the search content

 
^: B * $ \ n

Run againReplace allAll empty rows will disappear.

-----------------------------------------------

The reason is that only comment lines are removed because

 
IntA =0;//Interger with initial value 0.

The mixed comments are too complicated for me to handle. I have to make plans later.

How complicated is it? Here are a few examples.

 1   VaR Str1 = "  Hello  " ; //  VaR str1 = Hello "; think this is easy, ha?  2   VaR Str2 ="  Bye \"  " ; //  Bye "\". So, bite me  3   VaR Str3 = @"  This is called  4   Multiple line string.  ";   //  Kiss my ass, "Regular Expression" 

What should we do in these cases? Let's discuss it again.

Visual Studio deletes the source with search replacementCodeAll // methods in pure comments and empty rows

Note: XML annotations including // <summary> are also deleted.

Step 1/2 (Delete comment): Use the CTRL + H quick replacement function to find the following content:

 
^ [\ T] * // [^ \ n] * \ n

ReplaceNull(Do not write anything), you can set the search range (I like to selectEntire Solution). Select the search option.Use Regular Expressions. Then clickReplace allThat's all.

This will delete the comments of the original line/And leave no blank lines.

Step 2/2 (delete empty rows): then set the search content

 
^: B * $ \ n

Run againReplace allAll empty rows will disappear.

-----------------------------------------------

The reason is that only comment lines are removed because

IntA =0;//Interger with initial value 0.

The mixed comments are too complicated for me to handle. I have to make plans later.

How complicated is it? Here are a few examples.

 1   VaR Str1 = "  Hello  " ; //  VaR str1 = Hello "; think this is easy, ha?  2   VaR Str2 = "  Bye \" " ; //  Bye "\". So, bite me  3   VaR Str3 = @"  This is called  4   Multiple line string.  ";   //  Kiss my ass, "Regular Expression" 

What should we do in these cases? Let's discuss it again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.