Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何转换带有特殊字符的字符串,如下所示: małoletni => ma\u0142oletni Whereł转换为\u0142(与其余特殊字符相同)。
małoletni => ma\u0142oletni
ł
\u0142
我试过了
System.Text.UnicodeEncoding encoding = new System.Text.UnicodeEncoding();
但它返回奇怪的结果。
我怎样才能转换它?
var str = "małoletni\nPi(π)"; //ESCAPE var escaped = String.Join("", str.Select(c => c>31 && c < 128 ? c.ToString() : "\\u" + ((int)c).ToString("x4"))); //UNESCAPE var unescaped = Regex.Unescape(escaped)