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.

1
  • @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" Commented Jun 4, 2011 at 22:38

5 Answers 5

5

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, one of the answer there partially suits my question as well
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.

Comments

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!"; 

3 Comments

There is nothing wrong with doing it this way.
It depends on the context, really
@sehe What's wrong with that? You're not suggesting using a StringBuilder for that, are you?
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

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.