If you are getting a literal two-character \r
sequence out ("\\r"
in C# form), then that is almost certainly what you are putting in. You say your Web API method "looks a bit like this". I strongly suspect the problem lies in the difference between what you have posted in your question, and what is in your actual implementation.
You need to verify that your response message contains actual carriage returns and not the literal text "\r"
. A text reading API is not going to look for literal C# escape sequences and handle them specially because C# string escape sequences have no meaning in plain text. If your text file contained the text c:\name.txt
, then you wouldn't expect a text reading API to read it as c:<NEWLINE>ame.txt
.
If you want to find and convert C#-style escape sequences, you will have to do it yourself. You can use a method like this (add additional escape sequences as necessary):
private static string Unescape(string value) {
if (value == null)
return null;
var length = value.Length;
var result = new StringBuilder(length);
for (var i = 0; i < length; i++) {
var c = value[i];
if (c == '\\' && i++ < length) {
c = value[i];
switch (c) {
case 'n':
result.Append('\n');
break;
case 'r':
result.Append('\r');
break;
case 't':
result.Append('\t');
break;
case '\\':
result.Append('\\');
break;
default:
result.Append(c);
break;
}
}
else {
result.Append(c);
}
}
return result.ToString();
}
"\\r"
because@"\r"
is equivalent to"\\r"
. If you want to pass the return character instead of the escaped version, remove the verbatim modifier. – Redoubtable\\r
in a string if you want the ``. – Dysuria\r
in a text box is the string"\\r"
which is equal to@"\r"
. Remove the verbatim character. – Redoubtable