Unicode字符串 [英] Unicode characters string

查看:114
本文介绍了Unicode字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 String 个字符。

string s = "\\u0625\\u0647\\u0644";

打印上述序列时,我得到:

When I print the above sequence, I get:

\u0625\u0647\u062

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

How can I get the real printable Unicode characters instead of this \uxxxx representation?

我找到了答案:

s = System.Text.RegularExpressions.Regex.Unescape(s);


推荐答案

如果您真的不控制字符串,则您需要将这些转义序列替换为其值:

If you really don't control the string, then you need to replace those escape sequences with their values:

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

,希望您没有 \\ 也在其中逃脱。

and hope that you don't have \\ escapes in there too.

这篇关于Unicode字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆