Unicode 字符串 [英] Unicode characters string

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

问题描述

我有以下 String 字符.

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

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

When I print the above sequence, I get:

u0625u0647u062

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

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

推荐答案

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

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天全站免登陆