从其代码获取unicode字符串-C# [英] Getting unicode string from its code - C#

查看:49
本文介绍了从其代码获取unicode字符串-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道以下是在C#中使用unicode的方法

I know following is the way to use unicode in C#

string unicodeString = "\u0D15";

在我的情况下,我不会得到字符代码( 0D15 )在编译时。我在运行时从XML文件获得此信息。我想知道如何将此代码转换为unicode字符串吗?我尝试了以下操作

In my situation, I will not get the character code (0D15) at compile time. I get this from a XML file at runtime. I wonder how do I convert this code to unicode string? I tried the following

// will not compile as unrecognized escape sequence
string unicodeString = "\u" + codeFromXML; 

// will compile, but just concatenates u with the string got from XML file.
string unicodeString = "\\u" + codeFromXML; 

如何处理这种情况?

任何帮助都会很棒!

推荐答案

您要使用 char.ConvertFromUtf32 函数。

string codePoint = "0D15";

int code = int.Parse(codePoint, System.Globalization.NumberStyles.HexNumber);
string unicodeString = char.ConvertFromUtf32(code);
// unicodeString = "ക"

这篇关于从其代码获取unicode字符串-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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