C#.NET GB2312编码转化为中文
来源:互联网 发布:淘宝男装潮流店铺 编辑:程序博客网 时间:2024/05/22 15:47
代码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;namespace GB2312ConvertChinese{ class Program { static void Main(string[] args) { string content = "/HTC Butterfly X920e是刚刚推出不久的一款智能手机,该机的5.0英寸大屏&"; Console.WriteLine(GBKToChinese(content)); Console.ReadKey(); } static string GBKToChinese(string content) { string pattern = "&#(.+?);"; if (!Regex.IsMatch(content, pattern)) return content; MatchCollection collection = Regex.Matches(content, pattern); foreach (Match item in collection) { string GBK_Code = item.Value; string GBK_Value = item.Groups[1].Value; string chinese = ((char)Convert.ToInt32(GBK_Value, 10)).ToString(); content = content.Replace(GBK_Code, chinese); } return content; } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { //获得GB2312编码。 static void Main(string[] args) { string str = "研究中心"; StringBuilder sb = new StringBuilder(); foreach (char c in str) sb.AppendFormat("&#{0};", Convert.ToString((int)c, 10)); Console.WriteLine(sb.ToString()); Console.ReadKey(); } }}
参考:请问关于\u开头的汉字编码是什么类型的编码,c#怎样转换
URL:http://www.phpfans.net/ask/MTcyNzYzNw.html
unicode字符
如果是这样的string str = "\u5317\u4eac";
那直接输出就可以了
如果这个字符串是从其它地方得到的话,就这样:
- C# code
- string str = "\\u5317\\u4eac"; string[] temp = str.Split(new string[] { "\\u" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < temp.Length; i++) temp[i] = ((char)Convert.ToInt32(temp[i], 16)).ToString(); string result = string.Join("", temp); Console.WriteLine(result);
要从汉字转成unicode编码:
- C# code
- string str = "北京"; StringBuilder sb = new StringBuilder(); foreach (char c in str) sb.AppendFormat("\\u{0}", Convert.ToString((int)c, 16)); Response.Write(sb.ToString());
- C#.NET GB2312编码转化为中文
- 将中文转化为GB2312编码
- GB2312 转化为 UTF-8 中文乱码
- VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
- VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
- VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
- VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
- asp.net把utf-8编码转换为gb2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- xajax0.5中文乱码解决 服务器编码为gb2312时
- delphi中将UCS2编码的字符串转化为GB2312编码的简单方法
- asp.net 转换GB2312 的字符串为UTF8编码
- C+++Utf8字符转换Gb2312编码,解决TinyXml中文乱码
- Ext 之 tabPanel
- 《Effective STL》读书笔记八:Item 15:意识到string的不同实现 Item 16:如何将vector和string的数据传给老的API函数
- C#不安装Oracle Client时连接Oracle及“无法加载DLL: OraOps10.dll”错误
- 利用SQOOP将数据从数据库导入到HDFS
- AspNet上传文件的几个控件(downmoon收集)
- C#.NET GB2312编码转化为中文
- ZigBee学习笔记_HalDriverInit()_3
- centos 5.5如何配置vnc,开启linux远程桌面教程
- C#启动命令行进程,重定向标准输出流、標準輸入流和标准错误流
- Win7下Emacs间歇性变慢的问题
- APEX 发送邮件
- 配置
- Oracle补丁集的补丁号Patch ID/Number速查
- POJ 3273 Monthly Expense