Help with carriage return

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

How come this code doesn't seem to work?

textBox1.Text=textBox1.Text.Replace("\r\n\r\n","\r\n");

I want to remove all blank lines in a textBox.
 
Actually, after another test it seems like it might be working. Would
someone just verify that the code structure is correct?
 
No, that'd replace string literals, rather than escape sequences, and the
OP's code was fine.

I'd prefer the following though:

textBox1.Text=textBox1.Text.Replace(System.Environment.NewLine +
System.Environment.NewLine, System.Environment.NewLine);

Not as succinct, but more portable.
 
I'd prefer the following though:
textBox1.Text=textBox1.Text.Replace(System.Environment.NewLine +
System.Environment.NewLine, System.Environment.NewLine);

Not as succinct, but more portable.

Is there a reason you are using System.Environment.NewLine instead of
Environment.NewLine?
 
Keith Smith said:
Is there a reason you are using System.Environment.NewLine instead of
Environment.NewLine?

Just to make it clear to him what namespace it's in...
 
Back
Top