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-G
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).

posted @ Tuesday, March 04, 2008 4:28 PM

Print

Comments on this entry:

# re: Remove empty lines in text using Visual Studio.

Left by Rob at 5/15/2008 4:12 AM
Gravatar
Cool, thanks!

# re: Remove empty lines in text using Visual Studio.

Left by felipe at 5/30/2008 1:18 AM
Gravatar
Oh man i've been asking myself how to do this for years :D
thanks for the neat tip! this helped me a lot!!

# re: Remove empty lines in text using Visual Studio.

Left by Asbjorn at 7/31/2008 3:37 AM
Gravatar
Thanks alot :)

VS added 350.000 empty lines in one of my files..

# re: Remove empty lines in text using Visual Studio.

Left by Pete at 9/6/2008 4:34 AM
Gravatar
thanks! could you explain the regex? why is the newline character after the end of line marker?

# re: Remove empty lines in text using Visual Studio.

Left by Michael Freidgeim at 9/6/2008 2:42 PM
Gravatar
Pete,
I've added more info about regEx into my post.

Your comment:



 (will not be displayed)


 
 
 
Please add 6 and 3 and type the answer here:
 

Live Comment Preview:

 
«September»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011