473,413 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

C# line return character

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
Oct 14 '06 #1
5 31935
>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";
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Oct 14 '06 #2
"Jason Huang" <Ja************@hotmail.comwrote in message
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

Oct 14 '06 #3
Mattias Sjögren wrote:
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

Oct 16 '06 #4
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" <du******@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
Mattias Sjögren wrote:
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
Oct 16 '06 #5
Chris Dunaway <du******@gmail.comwrote:
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 - <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
Oct 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Wai Yip Tung | last post by:
When I do for line in fp: the line string usually has a '\n' at the end. In many cases I don't want the line break character. I can trim it using if line.endswith('\n'): line = line ...
1
by: Matt | last post by:
What is the syntax for line break character in javascript?? For example, the following code will yield error " unterminated string constant." If I put the following in one line, then no error. ...
5
by: Mark | last post by:
Is it possible to enter a line return into any other field other than text (such as number, currency or date/time)? How can a user be prevented from entering a line return into a field? ...
2
by: Paul | last post by:
Hello, Could someone remind me of how to insert a line-feed/return character, please? I have used it before, but I can't recall what it is. What I'm looking for IS NOT an escape character...
5
by: Alan Searle | last post by:
I am exporting ms-access data to XML files. This works fine. However, I need to insert one line at the top of each exported file (i.e. a reference to the XSL file) and am having a problem with...
4
by: micronack | last post by:
{NOTE . = space} I made a script to allow me to edit my webpages online through a text area in my cgi script but I've run into a problem. For whatever reason the text area seems to put spaces in...
3
by: ©® | last post by:
I have a whole lot of entries listed as: <image><filename> and would like to search and replace so the end result is so: <image> <filename> i.e. there is a return/enter after <image> I am...
1
by: TP | last post by:
Hi everybody, All my problem is in the title. If I try: $ python -c 'print "foo",' It does not change anything, surely because the line return is added by "python -c".
3
by: Ananthu | last post by:
Hi I have created one website named OTMS using ASP.NET in a File System Format.My project location is in F: drive(F:\Project\OTMS). I have installed IIS properly and the website runs properly in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.