您的位置:程序门 -> .net技术 -> c#



编码问题 utf-8 -> unicode


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


编码问题 utf-8 -> unicode[已结贴,结贴人:xmq120]
发表于:2007-08-12 19:56:56 楼主
如何把一个utf-8编码的改成   unicode   编码的文件?谢谢!
发表于:2007-08-12 19:59:181楼 得分:0
另存为的时候选择编码方式
发表于:2007-08-12 20:04:092楼 得分:0
....ls的大哥   我要想通过程序实现啊   不是手工修改啊     这样我自然也是会的   -_-!!!
发表于:2007-08-12 20:37:523楼 得分:0
string   unicodestring   =   "this   string   contains   the   unicode   character ";

encoding   ascii   =   encoding.utf8;
encoding   unicode   =   encoding.unicode;

byte[]   unicodebytes   =   unicode.getbytes(unicodestring);

byte[]   utf8bytes   =   encoding.convert(unicode,   ascii,   unicodebytes);

然后写入文件就可以了
发表于:2007-08-12 20:38:184楼 得分:50
string   encodedbyutf8   =   system.text.encoding.getencoding( "utf8 ").getstring(yourstringencodedbyunicode);
发表于:2007-08-12 20:39:525楼 得分:0
上面拼写有误,   yourstringencodedbyunicode其实应该是yourbytesencodedbyunicode
发表于:2007-08-12 20:42:266楼 得分:0
搞错...

encoding   utf8   =   encoding.utf8;
encoding   unicode   =   encoding.unicode;

byte[]   utf8   =   ...//读出文件的字节码

byte[]   unicodebytes   =   encoding.convert(utf8,   unicode,   unicodebytes);

然后写入文件就可以了
发表于:2007-08-12 20:43:367楼 得分:0
再更正(我今晚怎么拉....)
byte[]   unicodebytes   =   encoding.convert(utf8,   unicode,   unicodebytes);
-->
byte[]   unicodebytes   =   encoding.convert(utf8,   unicode,   utf8   );
发表于:2007-08-12 20:47:148楼 得分:50
最后一次更正,写完整点
=============================
encoding   utf8   =   encoding.utf8;
encoding   unicode   =   encoding.unicode;

byte[]   utf8bytes   =   file.readallbytes( "a.txt ")   //读出文件的字节码

byte[]   unicodebytes   =   encoding.convert(utf8,   unicode,   utf8bytes);

file.writeallbytes( "b.txt ",unicodebytes);         //写到新文件

出去吹吹风,有点烦躁
发表于:2007-08-12 20:59:319楼 得分:0
再顺便问个问题     如何读取   无后缀名文件中的内容
发表于:2007-08-12 21:12:0110楼 得分:0
一样,   把文件名当作路径就行


快速检索

最新资讯
热门点击