public static string ConvertQuotedString(string s)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < s.Length; ++i) {
char c = s[i];
if (c != '\\')
builder.Append(c);
else {
if (i == s.Length - 1)
break;
++i;
c = s[i];
if (c >= '0' && c <= '7') {
// Octal format.
int j;
for (j = i; j < s.Length; ++j) {
if (s[j] < '0' || s[j] > '7')
break;
}
string octal = s.Substring(i, j - i);
i = j - 1;
c = (char) Convert.ToInt16(octal, 8);
builder.Append(c);
}
else if (c == 'r') {
builder.Append('\r');
}
else if (c == 'n') {
builder.Append("\r\n");
}
else if (c == '"') {
builder.Append('"');
}
else if (c == '\\') {
builder.Append('\\');
}
else
builder.Append(c);
}
}
return builder.ToString();
}