Using StringBuilder and in my string I am using Environment.NewLine, when I open it it shows as CRLF, Is there another commands in C# that the output shows as "LF" only and not "CRLF"?
LF (character : \n, Unicode : U+000A, ASCII : 10, hex : 0x0a): This is simply the '\n' character which we all know from our early programming days. This character is commonly known as the 'Line Feed' or 'Newline Character'.
The Line Feed (LF) character moves the cursor down to the next line without returning to the beginning of the line. This character is used as the new line character in Unix based systems (Linux, macOS X, Android, etc). Codes Display.
In most C compilers, including ours, the newline escape sequence '\n' yields an ASCII line feed character. The C escape sequence for a carriage return is '\r'.
By using: \n – It prints new line. By using: \x0A or \xA (ASCII literal of \n) – It prints new line. By using: Console.
Simply write
sb.Append((char)10);
or more readable
sb.Append('\n');
even more readable
const char LF = '\n';
sb.Append(LF);
The Environment.NewLine
exists solely to differ between Windows-like line endings (\r\n
) and Unix-style line endings (\n
), so when writing text files and the like you don't have to bother which one to use (imagine you're running on Mono on Linux, then you want just \n
, which the Environment. NewLine
will contain as it is set by the runtime).
So when you know you always and only want a line feed character, simply put \n
in your code. It won't change.
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