I have a string that has special characters like this example: 12345678912\rJ\u0011 because I need to have access to this special chars to configure my application. I want to display this string exactly like this in a TextBox field so everything I have tried so far results in a string where the character \u0011
tries to render with an empty character at the end: "7896104866061\rJ"
.
I made this but it doesn't work.
string result = Regex.Replace(
ToLiteral(this.Buffer),
"[^\x00-\x7Fd]",
c => string.Format("\\u{0:x4}", (int)c.Value[0]))
.Replace(@"\", @"\\");
public static string ToLiteral(string input)
{
using (var writer = new StringWriter())
{
using (var provider = CodeDomProvider.CreateProvider("CSharp"))
{
provider.GenerateCodeFromExpression(
new CodePrimitiveExpression(input),
writer,
null);
return writer.ToString();
}
}
}
What need I do? Thanks in advance.
\u0011
?