Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 86 characters in body
Source Link
Shaun Luttin
  • 142.9k
  • 93
  • 443
  • 495

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else?

It is not a bug. CRLF is the default for the Environment.NewLine in Windows: a 'string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.'

How can we explain this?

It probably results from the way you are outputting the string values to a file. If you use a method that adds new lines (e.g., such as WriteAllLines()) does, then there will automatically be a CRLF at the end of each value you write.

For instance, if we can run the following program,.

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then we will produceIt produces two output files. The one on the left used WriteAllLines to write four lines. The one on the right used WriteAllText() and did not write any new lines.

enter image description here

AllIn both, all of the content outside of parentheses is independent of your code. That is, the CRLF symbols are part of writing a line in the call to WriteAllLines.

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else?

It is not a bug. CRLF is the default for the Environment.NewLine in Windows: a 'string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.'

How can we explain this?

It probably results from the way you are outputting the string values to a file. If you use a method that adds new lines (e.g. WriteAllLines()), then there will automatically be CRLF at the end of each value you write.

For instance, if we run the following program,

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then we will produce two output files. The one on the left used WriteAllLines to write four lines. The one on the right did not write any new lines.

enter image description here

All of the content outside of parentheses is independent of your code. That is, the CRLF symbols are part of writing a line in the call to WriteAllLines.

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else?

It is not a bug. CRLF is the default for the Environment.NewLine in Windows: a 'string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.'

How can we explain this?

It probably results from the way you are outputting the string values to a file. If you use a method that adds new lines, such as WriteAllLines() does, then there will automatically be a CRLF at the end of each value you write.

For instance, we can run the following program.

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

It produces two output files. The one on the left used WriteAllLines to write four lines. The one on the right used WriteAllText() and did not write any new lines.

enter image description here

In both, all of the content outside parentheses is independent of your code. That is, the CRLF symbols are part of writing a line in the call to WriteAllLines.

added 86 characters in body
Source Link
Shaun Luttin
  • 142.9k
  • 93
  • 443
  • 495

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else? How can we explain this?

It is not a bug. The CRLF is the default for the Environment.NewLine in Windows: a 'string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.'

A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.How can we explain this?

It is probably resultingresults from the way that you are outputting the string values to a file. If you are writing the string values with somethinguse a method that adds new lines (e.g. WriteAllLines()), then there will automatically be CRLF at the end of each value you write.

IfFor instance, if we run the following program,

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then itwe will produce two output files. The one on the left used WriteAllLines to write four lines. The one on the right did not write any new lines.

enter image description here

All of the content outside of parentheses is independent of your code. That is, the CRLF issymbols are part of writing a line in the call to WriteAllLines.

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else? How can we explain this?

It is not a bug. The CRLF is the default for the Environment.NewLine in Windows.

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

It is probably resulting from the way that you are outputting the string values. If you are writing the string values with something that adds new lines (e.g. WriteAllLines()), then there will automatically be CRLF at the end of each value.

If we run the following program,

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then it will produce two output files. The one on the left used WriteAllLines to write four lines. The one on the right did not write any new lines.

enter image description here

All of the content outside of parentheses is independent of your code. That is, the CRLF is part of writing a line in the call to WriteAllLines.

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else?

It is not a bug. CRLF is the default for the Environment.NewLine in Windows: a 'string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.'

How can we explain this?

It probably results from the way you are outputting the string values to a file. If you use a method that adds new lines (e.g. WriteAllLines()), then there will automatically be CRLF at the end of each value you write.

For instance, if we run the following program,

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then we will produce two output files. The one on the left used WriteAllLines to write four lines. The one on the right did not write any new lines.

enter image description here

All of the content outside of parentheses is independent of your code. That is, the CRLF symbols are part of writing a line in the call to WriteAllLines.

added 86 characters in body
Source Link
Shaun Luttin
  • 142.9k
  • 93
  • 443
  • 495

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else? How can we explain this?

It is not a bug. The CRLF is the default for the Environment.NewLine in Windows.

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

It is probably resulting from the way that you are outputting the string values. If you are writing the string values with something that adds new lines (e.g. WriteAllLines()), then there will automatically be CRLF at the end of each value.

If we run the following program,

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then it will produce two output files. The one on the left used WriteAllLines to write four lines. The one on the right did not write any new lines.

enter image description here

All of the content outside of parentheses is independent of your code. That is, the CRLF is part of writing a line in the call to WriteAllLines.

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else? How can we explain this?

The CRLF is the default for the Environment.NewLine.

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

If we run the following program,

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then it will produce two output files.

enter image description here

All of the content outside of parentheses is independent of your code. That is, the CRLF is part of writing a line in the call to WriteAllLines.

Interestingly you can see there no difference with \r and \n and for both of them it shows CR LF Is it a bug or something else? How can we explain this?

It is not a bug. The CRLF is the default for the Environment.NewLine in Windows.

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

It is probably resulting from the way that you are outputting the string values. If you are writing the string values with something that adds new lines (e.g. WriteAllLines()), then there will automatically be CRLF at the end of each value.

If we run the following program,

string r = "\r"; string n = "\n"; string CarriageReturn = (Convert.ToChar(13)).ToString(); string LineFeed = (Convert.ToChar(10)).ToString(); var content = new string[] { $"(r:{r})", $"(n:{n})", $"(13:{CarriageReturn})", $"(10:{LineFeed})" }; System.IO.File.WriteAllLines("output1.txt", content); System.IO.File.WriteAllText("output2.txt", string.Join("", content)); 

Then it will produce two output files. The one on the left used WriteAllLines to write four lines. The one on the right did not write any new lines.

enter image description here

All of the content outside of parentheses is independent of your code. That is, the CRLF is part of writing a line in the call to WriteAllLines.

added 86 characters in body
Source Link
Shaun Luttin
  • 142.9k
  • 93
  • 443
  • 495
Loading
Source Link
Shaun Luttin
  • 142.9k
  • 93
  • 443
  • 495
Loading