I am using C# on Visual Studio and have struggled with replacing the line breaks of the excel file.

I have tried the following commands, none of them can replace all the line breaks which exist in a cell of excel. (Even using all of them, there are still line breaks show as "LF" in Notepad++.)

answer = Regex.Replace(answer, @"\r\n?|\n", "<br>");
answer = answer.Replace(System.Environment.NewLine, "<br>");
answer = answer.Replace("\\n", "<br>");
answer = answer.Replace("\n", "<br>");
answer = answer.Replace("\r\n", "<br>");
answer = answer.Replace("\r", "<br>");

An example of the original cell looks like this:


Afterward the cell looks like this:

after replacing

I expect that there should be no line breaks shown as "LF" in Notepad++, but with the mentioned code, there are still a few "LF"s.

Thanks in advance!

0 Answers