Unicode字符串

Mar*_*son 20 c# unicode

我有以下String字符.

string s = "\\u0625\\u0647\\u0644";
Run Code Online (Sandbox Code Playgroud)

当我打印上面的序列时,我得到:

\u0625\u0647\u062
Run Code Online (Sandbox Code Playgroud)

如何获得真正可打印的Unicode字符而不是此\ uxxxx表示?


我找到了答案:

s = System.Text.RegularExpressions.Regex.Unescape(s);
Run Code Online (Sandbox Code Playgroud)

Joe*_*oey 5

如果你真的不控制字符串,那么你需要用它们的值替换这些转义序列:

Regex.Replace(s, @"\u([0-9A-Fa-f]{4})", m => ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString());
Run Code Online (Sandbox Code Playgroud)

并希望你\\在那里也没有逃脱。


Ruz*_*ihm 3

Asker 发布此内容作为对他们问题的回答:

我找到了答案:

s = System.Text.RegularExpressions.Regex.Unescape(s);
Run Code Online (Sandbox Code Playgroud)