如何实现UTF8解码与编码的问题??

xqiqi 2006-07-28 12:33:00
来自己文本文件(ANSI)中的一行:N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E5=AE=B6=E4=BA=BA

下面简要说明QUOTED-PRINTABLE编码方式,更为详细的资料请参考相关文档:
ASCII可显示字符基本保持不变。Unicode字符或者UTF8编码字符使用等号加其对应16进制代码表示。例如上述CHARSET为UTF8的字符=E5=AE=B6=E4=BA=BA对应的UTF8编码0xE5,0xAE,0xB6代表中文“家”,其他的代表“人”。另外如果其中有可显示ASCII码,保持原样输出。

例如ENCODING=QUOTED-PRINTABLE:Home=E5=AE=B6People=E4=BA=BA解码后为“Home家People人”。
Q:如何实现上述编码的转换(包括解码与编码的方法)?

谢谢~~
...全文
1766 41 打赏 收藏 转发到动态 举报
写回复
用AI写文章
41 条回复
切换为时间正序
请发表友善的回复…
发表回复
xqiqi 2006-08-03
  • 打赏
  • 举报
回复
谢谢 net_lover(【孟子E章】)
ericksky 2006-07-29
  • 打赏
  • 举报
回复
mark
viena 2006-07-28
  • 打赏
  • 举报
回复
using System;
using System.Text;

namespace ConvertExample
{
class ConvertExampleClass
{
static void Main()
{
string unicodeString = "This string contains the unicode character Pi(\u03a0)";

// Create two different encodings.
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;

// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);

// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);

// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);

// Display the strings created before and after the conversion.
Console.WriteLine("Original string: {0}", unicodeString);
Console.WriteLine("Ascii converted string: {0}", asciiString);
}
}
}
viena 2006-07-28
  • 打赏
  • 举报
回复
将字节数组内某个范围的字节从一种编码转换为另一种编码。

public static byte[] Convert(
Encoding srcEncoding,
Encoding dstEncoding,
byte[] bytes,
int index,
int count
);
viena 2006-07-28
  • 打赏
  • 举报
回复
Encoding.Convert
jack6512006 2006-07-28
  • 打赏
  • 举报
回复
encoding
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
太崇拜你了,收我为徒吧
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
恩,解决了啊...
我要拜孟子大哥为师啊,谁都不要拦我
孟子E章 2006-07-28
  • 打赏
  • 举报
回复
你可以先进行替换
str = str.Replace("==","=")
孟子E章 2006-07-28
  • 打赏
  • 举报
回复
不可以先进行替换
str = str.Replace("==","=")
孟子E章 2006-07-28
  • 打赏
  • 举报
回复
好像两个==是换行了
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
第二行81后面的=号不同
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
"=E4=BD=A0=E6=98=AF=E9=98=BF=E6=B2=99=E5=8D=A1=E6=AD=A6=E6=B6=B2=E5=8E=8B=E3=81==95=EF=BD=8A=EF=BD=88=E3=81=A5=E3=81=95=E3=81=98=EF=BD=93=E3=81=98=E3=81=86=E3==81=A9=E3=81=87=E7=AC=B9=E3=82=B9=E3=82=A7=E4=BA=9Csw"
这是收到的QP码
这时用你的方法得到"你是阿沙卡武液压さjhづさじsじうどぇ笹スェ亜sw"的QP:
"=e4=BD=A0=E6=98=AF=E9=98=BF=E6=B2=99=E5=8D=A1=E6=AD=A6=E6=B6=B2=E5=8E=8B=E3=81=95=EF=BD=8A=EF=BD=88=E3=81=A5=E3=81=95=E3=81=98=EF=BD=93=E3=81=98=E3=81=86=E3=81=A9=E3=81=87=E7=AC=B9=E3=82=B9=E3=82=A7=E4=BA=9Csw"
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
晕,刚才改了发信的,忘了改收信的了,不过还是不对啊
结果:"你是阿沙卡武液压%jhづさじsじう%ぇ笹スェ亜sw"
应该为:你是阿沙卡武液压さjhづさじsじうどぇ笹スェ亜sw
孟子E章 2006-07-28
  • 打赏
  • 举报
回复
你的编码和解码格式要一致,
System.Web.HttpUtility.UrlDecode(d, System.Text.Encoding.UTF8);
System.Web.HttpUtility.UrlEncode(a, System.Text.Encoding.UTF8);

tcx1986 2006-07-28
  • 打赏
  • 举报
回复
难道会是我用日文系统的原因?
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
等待孟子大哥...
tcx1986 2006-07-28
  • 打赏
  • 举报
回复
我用jmail发邮件发出的正文就是QP乱码啊
孟子E章 2006-07-28
  • 打赏
  • 举报
回复
编码解码都是你自己做的么?
jmail本身已经处理这些了,你怎么还自己写?
copall 2006-07-28
  • 打赏
  • 举报
回复
原来孟子在...
加载更多回复(21)

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧