Windows Phone 7 中将Gb2312编码转换成UTF-8
来源:互联网 发布:wp8怎么下载软件 编辑:程序博客网 时间:2024/05/22 14:32
相信大家在wp7开发时使用一些网站提供的API的时候会发现他们提供的API的编码是GB2312的,而wp7并不支持。
前一阵子我在做一个应用的时候也遇到了这个问题。群里的一个大大提供了两个类帮忙解决了这个问题。
/Files/Angle-Louis/GB2312相关的编码类.rar
那么如何使用这两个类呢?
比如您使用了Webclient从网络上获取资源,那么在Client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)函数中
byte[] txtBytes = StreamToBytes(e.Result);
Gb2312Encoding encoding = new Gb2312Encoding();
string str1 = encoding.GetString(txtBytes, 0, txtBytes.Length);
byte[] uftBytes = Encoding.UTF8.GetBytes(str1);
//System.Convert.FromBase64String(str1);
Stream utfStream = BytesToStream(uftBytes);
using (StreamReader UtfReader = new StreamReader(utfStream))
{
string Result = UtfReader.ReadToEnd();
//这里已经是Utf-8的编码了
}
Gb2312Encoding encoding = new Gb2312Encoding();
string str1 = encoding.GetString(txtBytes, 0, txtBytes.Length);
byte[] uftBytes = Encoding.UTF8.GetBytes(str1);
//System.Convert.FromBase64String(str1);
Stream utfStream = BytesToStream(uftBytes);
using (StreamReader UtfReader = new StreamReader(utfStream))
{
string Result = UtfReader.ReadToEnd();
//这里已经是Utf-8的编码了
}
public byte[] StreamToBytes(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}
public Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
}
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}
public Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
}
- Windows Phone 7 中将Gb2312编码转换成UTF-8
- Windows Phone 7 中将Gb2312编码转换成UTF-8
- 编码转换utf-8/gb2312
- 字符集编码之间的转换,UTF-8 转为 GB2312,GB2312 转为 UTF-8 ,Unicode 转换成UTF-8
- 字符集编码之间的转换,UTF-8 转为 GB2312,GB2312 转为 UTF-8 ,Unicode 转换成UTF-8
- gb2312与utf-8网页编码转换
- PERL GB2312 UTF-8 编码转换
- C++转换unicode utf-8 gb2312编码
- 【Java】编码转换:UTF-8转GB2312
- GB2312编码与UTF-8编码的相互转换代码(linux windows下通用)
- UTF-8 转换成 GB2312
- Windows API GB2312/Unicode/UTF-8转换
- Windows API GB2312/Unicode/UTF-8转换
- 把UTF-8编码转换为GB2312编码
- 把UTF-8编码转换为GB2312编码[转]
- 把UTF-8编码转换为GB2312编码[转]
- asp.net把utf-8编码转换为gb2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- 普通应用使用Surface的方法
- 面向对象编程的初步
- window phone 独立存储空间的操作
- 清除mac 系统终端的历史命令记录
- Hough变换原理
- Windows Phone 7 中将Gb2312编码转换成UTF-8
- 【tarjan求割边】PKU-3694-Network
- Oracle基础学习笔记(四)(VIEW)
- EasySYS开发驱动在调试版运行时注意的问题(1)
- 关于安装sql sever 2005的相关问题
- VS2010 中的 C++ 0x 新特性:Lambdas、auto 和 static_assert
- WP7开发学习(4):Style样式的四种使用
- jquery插件实现图片的左右滚动
- 任重而道远