473,725 Members | 2,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Environment.New line

Hi

I would like to ask a little bit about the value Environment.New line: what
is it and what is the point of it? Ok, I can see in the docs that it
represents "newline" for the current platform - I assume that it is a
runtime property, and not compile time?

But won't it always be the same anyway - does dotnet run on anything other
than windows platforms? So isn't newline always the same?

And what if I have a program that uses "Environment.Ne wline" to generate a
string and send it to a program running on another platform - the other
platform might have a completely different "newline" concept, and therefore
to use Environment.New line is pointless isn't it?

Thanks for any comments,
Peter
Apr 3 '06 #1
4 4485
C# implementations do not always run on Windows, no. Google for
"rotor", "mono", and "dotgnu" individually and you'll find examples of
non-Windows implementations of the C# language, compiler, and runtime
environment. as far as I know, the mono project is the furthest
advanced. they have a complete 1.1 environment written, and its all
open source. it compiles and runs anywhere Unix or Windows does.

Also, should it be the responsibility of the programmer to know exactly
what the newline character is on any given system? personally, I don't
think it should be. True, there are only two types of newline currently
if you only count the latest PC operating systems, and hopefully that
narrows to one in the future, but should it be the responsibility of the
programmer to determine what operating system he is on and write logic
that outputs the currect system newline?

jeremiah
Peter Kirk wrote:
Hi

I would like to ask a little bit about the value Environment.New line: what
is it and what is the point of it? Ok, I can see in the docs that it
represents "newline" for the current platform - I assume that it is a
runtime property, and not compile time?

But won't it always be the same anyway - does dotnet run on anything other
than windows platforms? So isn't newline always the same?

And what if I have a program that uses "Environment.Ne wline" to generate a
string and send it to a program running on another platform - the other
platform might have a completely different "newline" concept, and therefore
to use Environment.New line is pointless isn't it?

Thanks for any comments,
Peter

Apr 3 '06 #2

"jeremiah johnson" <na*******@gmai l.com> skrev i en meddelelse
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Peter Kirk wrote:
Hi

I would like to ask a little bit about the value Environment.New line:
what is it and what is the point of it? Ok, I can see in the docs that it
represents "newline" for the current platform - I assume that it is a
runtime property, and not compile time?

But won't it always be the same anyway - does dotnet run on anything
other than windows platforms? So isn't newline always the same?

And what if I have a program that uses "Environment.Ne wline" to generate
a string and send it to a program running on another platform - the other
platform might have a completely different "newline" concept, and
therefore to use Environment.New line is pointless isn't it?

Thanks for any comments,
Peter

C# implementations do not always run on Windows, no. Google for "rotor",
"mono", and "dotgnu" individually and you'll find examples of non-Windows
implementations of the C# language, compiler, and runtime environment. as
far as I know, the mono project is the furthest advanced. they have a
complete 1.1 environment written, and its all open source. it compiles
and runs anywhere Unix or Windows does.

Also, should it be the responsibility of the programmer to know exactly
what the newline character is on any given system? personally, I don't
think it should be. True, there are only two types of newline currently
if you only count the latest PC operating systems, and hopefully that
narrows to one in the future, but should it be the responsibility of the
programmer to determine what operating system he is on and write logic
that outputs the currect system newline?


OK, I wasn't aware that .net applications could run on other platforms -
that's great. In that case I agree it is good to have a runtime property for
such things as newline (which can vary from platform to platform).

But how do you cope with sending messages from one application to another -
where we don't know what platforms the applications are running on?

For example, my application running on a windows machine generates a string
like "hello\r\n" (where "\r\n" is the Environment.New line), and sends this
string to another application which just happens to have been installed on a
unix machine. This machine only uses "\n" characters as newline - won't
there be problems when it sees "\r\n"? Likewise, the application on the unix
machine could send a string "hello\n" (where "\n" is Environment.New line on
unix) to the application running on windows - the application on windows
expects "\r\n".
Peter
Apr 3 '06 #3
"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:u0******** ******@TK2MSFTN GP14.phx.gbl...

"jeremiah johnson" <na*******@gmai l.com> skrev i en meddelelse
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Peter Kirk wrote:
Hi

I would like to ask a little bit about the value Environment.New line:
what is it and what is the point of it? Ok, I can see in the docs that
it represents "newline" for the current platform - I assume that it is a
runtime property, and not compile time?

But won't it always be the same anyway - does dotnet run on anything
other than windows platforms? So isn't newline always the same?

And what if I have a program that uses "Environment.Ne wline" to generate
a string and send it to a program running on another platform - the
other platform might have a completely different "newline" concept, and
therefore to use Environment.New line is pointless isn't it?

Thanks for any comments,
Peter

C# implementations do not always run on Windows, no. Google for "rotor",
"mono", and "dotgnu" individually and you'll find examples of non-Windows
implementations of the C# language, compiler, and runtime environment.
as far as I know, the mono project is the furthest advanced. they have a
complete 1.1 environment written, and its all open source. it compiles
and runs anywhere Unix or Windows does.

Also, should it be the responsibility of the programmer to know exactly
what the newline character is on any given system? personally, I don't
think it should be. True, there are only two types of newline currently
if you only count the latest PC operating systems, and hopefully that
narrows to one in the future, but should it be the responsibility of the
programmer to determine what operating system he is on and write logic
that outputs the currect system newline?


OK, I wasn't aware that .net applications could run on other platforms -
that's great. In that case I agree it is good to have a runtime property
for such things as newline (which can vary from platform to platform).

But how do you cope with sending messages from one application to
another - where we don't know what platforms the applications are running
on?

For example, my application running on a windows machine generates a
string like "hello\r\n" (where "\r\n" is the Environment.New line), and
sends this string to another application which just happens to have been
installed on a unix machine. This machine only uses "\n" characters as
newline - won't there be problems when it sees "\r\n"? Likewise, the
application on the unix machine could send a string "hello\n" (where "\n"
is Environment.New line on unix) to the application running on windows -
the application on windows expects "\r\n".


That's basically correct. And until the world decides on a single form of
newline, we still have to handle this situation ourselves. I believe that
is why most internet protocols either define what sort of newline will be
used or do not use a newline at all - they cannot depend on the OS
implementations to be consistent.

--
Adam Clauss
Apr 3 '06 #4
cross-platform newlines are handled usually by XML. XML parsers
completely ignore whitespace, so newlines of any kind are just not paid
attention to.

that's how i handle cross-platform text transfer, anyway. i wrap it up
in lightweight xml in a way that makes each new line a seperate tag,
and send it that way.

i'm sure there are other ways to handle this. if you control the
applications on both ends of the connection you could simply code-in an
agreed upon character that represents newlines and honor that.

Apr 3 '06 #5

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

Similar topics

5
25554
by: Liang | last post by:
hi, I want to convert a file from dos formate to unix format. This is very easy in unix. But in dos environment, the script can't work. The perl version I used is:5.001. Anyone knows the clue? thanks in advance,
5
57199
by: Vamsi | last post by:
Hi, I am trying a basic opearation of splitting a multiline value to an array of single lines(Actually making Address into AddressLine1, AddressLine2). I used Environment.NewLine in split, I could get only 1st line, but it is not returning 2nd line. here's code: string address = null; string ssep = Environment.NewLine; char sep = ssep.ToCharArray();
13
2193
by: John Bowman | last post by:
Hi All, I've got a simple wrapper static test method on a class to expand the environment variables on a specified string: public static string ExpandEnvironmentStr(string Str) { return Environment.ExpandEnvironmentVariables(Str); }
1
6198
by: Asha | last post by:
greetings... i want to split a new line from an input text area and here's what i did string.Split("\n \r ", ","); the result, nothing happen... then i tried this string.Split(Environment.NewLine, ",");
2
2129
by: Kevin Blount | last post by:
I've been trying all morning to find a way that will let me add new lines to a string that will form the body of an email. The problem is that some lines are not appearing as new line, but rather are being appended to existing lines. Here's my (cut down) code: string sbInstructions = string.Empty; char endOfLine = '\n'; sbInstructions += "" + endOfLine; sbInstructions += "DupCheck=email" + endOfLine;
11
6247
by: rossum | last post by:
I want to declare a const multi-line string inside a method, and I am having some problems using Environment.NewLine. I started out with: class foo { public void PrintStuff() { const string multiline = "The first line." + Environment.NewLine +
1
8511
by: linq936 | last post by:
Hi, I read in many places that the string to be outputted by printf() must be ending with newline, for example, it should be printf("Hello World.\n"); instead of printf("Hello World.");
23
4277
by: O_TEXT | last post by:
When opening a file with open and O_TEXT, in microsoft environment, and then reading it with read, it is done in text mode. What does text mode exactly mean? How is it handled in reading? How is it handled in writing? does text mode has an impact on function returning position within the
0
3473
by: Cameron Simpson | last post by:
On 17Aug2008 21:25, John Nagle <nagle@animats.comwrote: Because $HOSTNAME is a bash specific variable, set by bash but NOT EXPORTED! Like $0 and a bunch of other "private" variables, subprocesses do not inherit this value. From "man bash": Shell Variables The following variables are set by the shell:
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9174
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8096
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.