会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
每天进步一点点
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
公告
Unicode转汉字的实现
Posted on
2007-06-01 16:35
单摆
阅读(
2365
) 评论(
4
)
收藏
举报
private
string
UnicodeToGB(
string
content)
{
Regex objRegex
=
new
Regex(
"
&#(?<UnicodeCode>[\\d]{5});
"
, RegexOptions.IgnoreCase);
Match objMatch
=
objRegex.Match(content);
StringBuilder sb
=
new
StringBuilder(content) ;
while
(objMatch.Success)
{
string
code
=
Convert.ToString(Convert.ToInt32(objMatch.Result(
"
${UnicodeCode}
"
)),
16
);
byte
[] array
=
new
byte
[
2
];
array[
0
]
=
(
byte
)Convert.ToInt32(code.Substring(
2
),
16
);
array[
1
]
=
(
byte
)Convert.ToInt32(code.Substring(
0
,
2
),
16
);
sb.Replace(objMatch.Value,Encoding.Unicode.GetString(array));
objMatch
=
objMatch.NextMatch();
}
return
sb.ToString();
}
刷新页面
返回顶部
博客园
© 2004-2025
浙公网安备 33010602011771号
浙ICP备2021040463号-3