Windows Phone 7 中将Gb2312编码转换成UTF-8
来源:互联网 发布:淘宝旺铺专业版怎么用 编辑:程序博客网 时间:2024/05/16 03:28
相信大家在使用一些网站提供的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编码
- Windows Phone网络HttpWebRequest用法
- 联想利泰的一道做出来就给月薪7K的面试题--交通灯管理系统
- 02_JDBC编程
- sqlite数据库文件拷贝出错
- js生成web安全色
- Windows Phone 7 中将Gb2312编码转换成UTF-8
- The Hadoop Distributed File System
- 百度Mp3的API在windows phone 7中的使用
- 用Maven建立一个web project
- 木马编写小技巧(转)
- 指针的底层实现
- Ubuntu下Eclipse CDT 代码悬浮提示窗口背景黑色设置方法
- 关于sqlite的特殊字符转义
- JVM调优总结