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)?
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.
In the VB.NET programming language, you can access the Environment. NewLine property. This leads to clear and readable code. Property. Special constant.
In the resource editor, while editing the string press Shift+Enter to insert a New Line.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With