Escape Characters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have just started doing some exercises in C# and have a question about
carriage return and new line escape characters. The code is concatenating the
text values from two textboxes and both the \r (carriage return) and \n (new
line) escape characters are used between the two strings. Could you not just
use one or the other?

Code:

string output;

output = "Name: " + this.txtName.Text + "\r\n";
output += "Address: " = this.txtAddress.Text;

TIA
Rowan
 
Well, generally, the line feed character (\n) should be enough.

But if you want to be 100% sure that it will work in every possible
environment, you could rewrite it as:

output
= "Name" this.txtName.Text
+ System.Environment.NewLine
;

output
+= "Address: " + this.txtAddress.Text;
 
Back
Top