Remove empty lines in text using Visual Studio.

Visual Studio has ability to delete empty lines in replace operation using regular expressions.
1.Click Ctrl-H (quick replace)
2. Tick "Use Regular Expressions"
3. In Find specify ^$\n
4. In Replace box delete everything.
5 Click "Replace All"
All empty lines will be deleted.

 Regular expression for empty line consist of   

Beginning of line ^

 

 

End of line $

 

Line break \n

 

Note that normally in Windows an end of line  indicated by 2 characters CRLF - Carriage Return (CR, ASCII 13, \r) Line Feed (LF, ASCII 10, \n).

Addition from  Kenneth at 6/18/2009:
A regex to remove blank lines that are/aren't *really* blank (i.e. they do/don't have spaces):   ^:b*$\n

Addition from   Igor  at 8/5/2011:

To remove double lines:  ^:b*\n:b*\n replace with:  \n

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
«March»
SunMonTueWedThuFriSat
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345