I have no idea how to show weird character code.
example \n
, \u0003
. I want to show it "\n"
or "\u0003"
on textbox, i.e. I don't want to show the symbol itself but its code.
any idea?
thank you so much
I have no idea how to show weird character code.
example \n
, \u0003
. I want to show it "\n"
or "\u0003"
on textbox, i.e. I don't want to show the symbol itself but its code.
any idea?
thank you so much
If you want to encode the string, i.e. to represent control characters with their codes (for instance for some kind of logging, debugging etc.)
using System.Linq;
...
private static string Encode(string value) {
if (null == value)
return null;
return string.Concat(value
.Select(c => char.IsControl(c)
? $"\\u{((int) c):x4}" // control symbol - as a code
: c.ToString())); // non-control - as it is
}
Then
myTextBox.Text = Encode("abc\ndef\r\t566");
And you'll have
abc\u000adef\u000d\u0009566