By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,205 Members | 1,482 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,205 IT Pros & Developers. It's quick & easy.

Environment.Newline

P: n/a
Hi

I would like to ask a little bit about the value Environment.Newline: 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.Newline" 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.Newline is pointless isn't it?

Thanks for any comments,
Peter
Apr 3 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.Newline: 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.Newline" 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.Newline is pointless isn't it?

Thanks for any comments,
Peter

Apr 3 '06 #2

P: n/a

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

I would like to ask a little bit about the value Environment.Newline:
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.Newline" 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.Newline 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.Newline), 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.Newline on
unix) to the application running on windows - the application on windows
expects "\r\n".
Peter
Apr 3 '06 #3

P: n/a
"Peter Kirk" <pk@alpha-solutions.dk> wrote in message
news:u0**************@TK2MSFTNGP14.phx.gbl...

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

I would like to ask a little bit about the value Environment.Newline:
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.Newline" 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.Newline 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.Newline), 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.Newline 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.