How to delete multiple blank lines from text file


#1

hi…
I want to delete multiple blank lines from a text file. below is the text file for the reference.

More Options

Prasad

Loading more results…

Add

Options

Anant

qwerty


#2

Hi.

Well one way is to use the Join and Split methods…
Split by the Newline then join back together.

String.Join(System.Environment.Newline, text.Split({System.Environment.Newline},System.StringSplitOptions.RemoveEmptyEntries) )

Another way would be to use Replace…
Assuming there are 2 Newlines together

text.Replace(System.Environment.Newline+System.Environment.Newline, System.Environment.Newline)

Regards.


#3

Thank you very much ClaytonM. It worked for me :slight_smile: