471,318 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

\n\r in text box

Ant
Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;

Thanks very much in advance
Ant
Jan 18 '06 #1
5 14506
Ant <An*@discussions.microsoft.com> wrote:
Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;


Use CR LF rather than LF CR:

displayText = "Hello world line one\r\nHello world line two";

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 18 '06 #2
Ant wrote:
Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;

Thanks very much in advance
Ant


textbox.multiline = true;
displayText = "Hello world line one\r\nHello world line two";

your carriage return is in the wrong order

\n\r = wrong
\r\n = right
Jan 18 '06 #3
Ant
So simple!

Thank you again
Ant

"Jon Skeet [C# MVP]" wrote:
Ant <An*@discussions.microsoft.com> wrote:
Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;


Use CR LF rather than LF CR:

displayText = "Hello world line one\r\nHello world line two";

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 18 '06 #4
You could also use Environment.NewLine instead of \r\n. This is "safer" in
the longrun since Unix/Linux uses \n and Macintosh uses \r, your code will
run correctly on that type of box in the event of your application running
under something like Mono.

"Ant" wrote:
So simple!

Thank you again
Ant

"Jon Skeet [C# MVP]" wrote:
Ant <An*@discussions.microsoft.com> wrote:
Hi, I'm using \n\r to attempt to carriage return a string which will be
displayed in a text box, however, the line remains one line. How do I cariage
return a string being displayed in a text box?

e.g.
displayText = "Hello world line one\n\rHello world line two";
textbox.text = displayText;


Use CR LF rather than LF CR:

displayText = "Hello world line one\r\nHello world line two";

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 18 '06 #5
Neyah <Ne***@discussions.microsoft.com> wrote:
You could also use Environment.NewLine instead of \r\n. This is "safer" in
the longrun since Unix/Linux uses \n and Macintosh uses \r, your code will
run correctly on that type of box in the event of your application running
under something like Mono.


Well, that really depends on what Mono chooses to do with TextBoxes.
There'll be a lot of code which uses Environment.NewLine, and a lot of
code which uses \r\n. Whatever they choose to do, they'll break a lot
of code.

Environment.NewLine is just the default new line string for text files
on that system IMO (and it's not very clearly documented, so it really
is just my opinion) - it needn't dictate what a UI chooses to use.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 18 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Xerxes | last post: by
2 posts views Thread by Macsicarr | last post: by
40 posts views Thread by aku | last post: by
2 posts views Thread by Guoqi zheng | last post: by
3 posts views Thread by Greg Noss | last post: by
3 posts views Thread by | last post: by
17 posts views Thread by =?Utf-8?B?TWljaGVsIFBvc3NldGggW01DUF0=?= | last post: by
9 posts views Thread by scripteaze | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.