0

How can I remove empty line from a string for example:

Turn this:

enter image description here

to This:

enter image description here

I used this code text.Replace("\n",""); but it turns it to:

testtesttes

JeanLuc
  • 4,783
  • 1
  • 33
  • 47
Smaika
  • 1,187
  • 4
  • 12
  • 20

2 Answers2

3
    string data = stringData.Replace("\r\n\r\n", "\r\n"); 
Hitesh Thakor
  • 471
  • 2
  • 12
3

You should replace two newline characters(if any). Following code will work on Unix as well as non unix platforms.

var stringWithoutEmptyLines = yourString.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
Kamalesh Wankhede
  • 1,475
  • 16
  • 37