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.

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

Left by Sung at 10/2/2008 9:53 AM
Gravatar
thanks for the tips.
after playing with it, i find \t\n with wildcards configuration do the works too.

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

Left by Ross Youngblood at 10/20/2008 8:50 AM
Gravatar
This doesn't work in Visual Studio 6.0 (As far as I could tell.) Yes we are stuck in the dark ages.
I suppose I could download Emacs... and be done with this problem.

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

Left by Michael Freidgeim at 10/20/2008 10:06 PM
Gravatar
Ross,
You also can download Visual Studio 2008 Express, which is a good editor (even if you have to compile in Visual Studio 6.0)

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

Left by shophola at 4/27/2009 3:45 PM
Gravatar
cool! tips :D

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

Left by Gyanendra Kumar Mishra at 5/18/2009 2:47 PM
Gravatar
Thanks really this code is a life saver

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

Left by Kenneth at 6/18/2009 3:28 PM
Gravatar
I would offer an addendum:

A regex to remove blank lines that are/aren't *really* blank (i.e. they do/don't have spaces):

^:b*$\n

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

Left by Steven Chalk at 8/23/2009 6:18 AM
Gravatar
simple when you see the answer but I wasted and hour or so trying combinations until I found this solution. Well done.

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345