I’m trying to replace all carrage returns with a <br/> tag in C#. I thought this would take care of everything:
StringBuilder sb = new StringBuilder(s);
sb.Replace(System.Environment.NewLine, @"<br/>");
But apparently not. It doesn’t seem to catch CR+LF.
That will work if
Environment.NewLineis CR+LF, which it’s likely to be on Windows. Of course it won’t catch the situation where the string actually only contains line feeds, or only contains carriage returns. Perhaps you want:(Note that there’s no point in using a verbatim string literal for
"<br/>"as there’s no backslash in the string, and it’s a single line.)