Escape Characters

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
 
M

Mohammad

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;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top