I wanto to convert the string like “123” to string like “\u0031\u0032\u0033”.
How can i do this in .NET?
For example: reverse convert:
Encoding enc = Encoding.GetEncoding("us-ascii",
new EncoderExceptionFallback(),
new DecoderExceptionFallback());
byte[] by = enc.GetBytes(s);
string ans = enc.GetString(by);
return ans;
Strings in .NET already are Unicode, so there’s no need to convert them from Unicode to Unicode.
If you want to output a unicode escaped string, then try this:
Result:
See it working online: ideone
In .NET 4.0 you can omit the call to
ToArray.