5

Possible Duplicate:
Difference between “\n” and Environment.NewLine

Hello all!

The way I understand it, when we use . symbol in format string for double, it doesn't mean "dot", it actually means "decimal separator used in current environment", so if we are working with non-US culture settings, the output can be 2,00 instead of 2.00. That's quite handy.

Now, is it also true for \n (LF) special symbol? Will it become System.Environment.NewLine symbol when the format string gets parsed or will it always be 0x0A value regardless of system settings? Environment.NewLine is kinda wordy and I wonder if I can just use \n safely instead.

Thanks in advance.

Community
  • 1
  • 1
Dyppl
  • 12,161
  • 9
  • 47
  • 68
  • @jayrdub: yes, I know that, but that's exactly what I'm asking - whether `\n` means "\n" or "whatever endline symbols used in current environment" – Dyppl Jun 04 '11 at 22:38

5 Answers5

5

This is may be your answer Difference between "\n" and Environment.NewLine

Community
  • 1
  • 1
Amit
  • 21,570
  • 27
  • 74
  • 94
2

The point of using it is for portability between OSs

http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx

A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.

JeremyWeir
  • 24,118
  • 10
  • 92
  • 107
1

If you don't like typing out System.Environment.NewLine set a local var to that value.

string n = System.Environment.NewLine;
string stringWithStuff = "text!" + n + "moretext!";
Biff MaGriff
  • 8,102
  • 9
  • 61
  • 98
0

You should probably aware that text writers have a NewLine property too

i.e.

using System;

//  ...
Console.Write("eenie{0}meenie{0}minie{0}moe", Console.NewLine);
Console.Out.Write("eenie{0}meenie{0}minie{0}moe", Console.Out.NewLine);
Console.Error.Write("eenie{0}meenie{0}minie{0}moe", Console.Error.NewLine);

I'm not too sure from the top of my head whether that would always by definition be the same as System.Environment.NewLine. Cf. the docs

sehe
  • 374,641
  • 47
  • 450
  • 633
0

Refering to Environment.NewLine Property:

A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.

Also:

The property value of NewLine is a constant customized specifically for the current platform and implementation of the .NET Framework.

NewLine can be used in conjunction with language-specific newline support such as the escape characters '\r' and '\n' in Microsoft C# and C/C++, or vbCrLf in Microsoft Visual Basic.

Akram Shahda
  • 14,655
  • 4
  • 45
  • 65