Connecting Tech Pros Worldwide Forums | Help | Site Map

C# line return character

Jason Huang
Guest
 
Posts: n/a
#1: Oct 14 '06
Hi,

In my C# windows form project, how to use the line return character in a
string so the string will go to a new line?
Thanks for help.


Jason



Mattias Sjögren
Guest
 
Posts: n/a
#2: Oct 14 '06

re: C# line return character


>In my C# windows form project, how to use the line return character in a
Quote:
>string so the string will go to a new line?
string s = "First line" + Environment.NewLine + "Second line";


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Chris Mullins
Guest
 
Posts: n/a
#3: Oct 14 '06

re: C# line return character


"Jason Huang" <JasonHuang8888@hotmail.comwrote in message
Quote:
In my C# windows form project, how to use the line return character in a
string so the string will go to a new line?
Thanks for help.
string s = "hello" + Environment.NewLine + "world.";

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins



Chris Dunaway
Guest
 
Posts: n/a
#4: Oct 16 '06

re: C# line return character


Mattias Sjögren wrote:
Quote:
Quote:
In my C# windows form project, how to use the line return character in a
string so the string will go to a new line?
>
string s = "First line" + Environment.NewLine + "Second line";
>
>
Doesn't C# treat the "\r\n" as an alias for Environment.NewLine?
Wouldn't the code be more readable as:

string s = "First line\r\nSecondLine";

Just wondering,

Chris

Kevin Spencer
Guest
 
Posts: n/a
#5: Oct 16 '06

re: C# line return character


Doesn't C# treat the "\r\n" as an alias for Environment.NewLine?

It does in a Windows Environment, but not necessarily.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.

"Chris Dunaway" <dunawayc@gmail.comwrote in message
news:1161013339.392943.17850@k70g2000cwa.googlegro ups.com...
Mattias Sjögren wrote:
Quote:
Quote:
In my C# windows form project, how to use the line return character in a
string so the string will go to a new line?
>
string s = "First line" + Environment.NewLine + "Second line";
>
>
Doesn't C# treat the "\r\n" as an alias for Environment.NewLine?
Wouldn't the code be more readable as:

string s = "First line\r\nSecondLine";

Just wondering,

Chris


Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#6: Oct 16 '06

re: C# line return character


Chris Dunaway <dunawayc@gmail.comwrote:
Quote:
Doesn't C# treat the "\r\n" as an alias for Environment.NewLine?
Wouldn't the code be more readable as:
>
string s = "First line\r\nSecondLine";
Environment.NewLine ends up as "\r\n" on Windows, but won't on other
platforms.

Whether you should use "\r\n" or Environment.NewLine depends on the
context - it's not always a straightforward choice.

--
Jon Skeet - <skeet@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
Closed Thread