这是一个示例输入:"\\u0434\\u0430\\u043C\\u043E"
我想将其转换为可读的文本。如果它仍然可以带有重音符号,我将不胜感激。输入实际上可以比此更长,但是可以用作样本。
是的,我看到了(http://www.joelonsoftware.com/articles/Unicode.html)和(如何打印/存储非ASCII字符(unicode?)),但是它没有回答我的问题,所以请不要贴标签这是重复的。我将很高兴在C#中获得示例代码。我也尝试了HttpUtility.HtmlDecode(),但实际上并没有对其进行解码。这是代码:
//this is coming from service call and its comming just like this.
var str="\\u0434\\u0430\\u043C\\u043E";
var decoded = HttpUtility.HtmlDecode(str); // this doesn't work. Its returning the string str as is.
附带说明:以下将起作用。但是我的输入不是那样。
//Although my input isn't in the following form, the following works. But my input isn't in this form.
var str2="\u0434\u0430\u043C\u043E";
var decoded = HttpUtility.HtmlDecode(str2);
我如何正确地将类似““ \ u0434 \ u0430 \ u043C \ u043E”的字符串解码为可读文本。
我终于让它工作了:
我通过使用Regex.Unscape()方法使其工作。如果其他人遇到相同的问题,请按以下步骤解决问题:
var str = "\\u0434\\u0430\\u043C\\u043E";
var decoded = HttpUtility.HtmlDecode(Regex.Unescape(str)); //take a look the Regex.Unscape() call.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句