Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the value of Environment.NewLine?

Tags:

c#

.net

newline

I'm working with a library that uses Environment.NewLine as it's newline char when writing a file. I need it to write Unix formatted files, and as such would like to change the newline char.

Can I change the value of Environment.NewLine?

Any other ideas (aside from converting the file post creation)?

like image 492
TheSoftwareJedi Avatar asked Feb 20 '09 15:02

TheSoftwareJedi


People also ask

What is the use of environment NewLine in C#?

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. NewLine is automatically appended to text processed by the Console. WriteLine and StringBuilder. AppendLine methods.

What is environment NewLine in VB net?

In the VB.NET programming language, you can access the Environment. NewLine property. This leads to clear and readable code. Property. Special constant.

How do you make a new line in VB net?

In the resource editor, while editing the string press Shift+Enter to insert a New Line.


1 Answers

Can I change the value of Environment.NewLine?

No. If you know which platform to write for, create classes for each of these platforms and let them have their own implementation. In the simplest case, this would look as follows:

public abstract class Platform { public abstract string Newline { get; } }

public sealed class Unix : Platform {
    public override string Newline { get { return "\n"; } }
}

etc., and then just use an instance of the appropriate class.

like image 98
Konrad Rudolph Avatar answered Oct 24 '22 16:10

Konrad Rudolph