更改字符串的编码-C# [英] Change encoding of a string - C#
本文介绍了更改字符串的编码-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何更改字符串编码.
在此先感谢
关于
I want to know how can i change an string encoding.
Thanks in advance
Regards
推荐答案
本质上是将原始字符串转换为字节数组,然后使用所需的编码将字节数组转换回字符串的过程.为此,您使用Encoding类,这里有一个您正在做的示例 ^ ](位于底部附近),除了它采用ASCII并输出UTF-8.原理是一样的.
请注意,要在流上使用它,您需要进行缓冲,但是此过程要简单得多,因为您已经从输入缓冲区中获取了已编码的字节数组,并且Encode
方法为您的输出缓冲区返回了一个字节数组.
通过查看注释(如下),看起来OP似乎存在html编码问题.可以使用此 [
Essentially the process it to convert the original string into an array of bytes and the convert the array of bytes back into a string using the encoding you want. To do this you use the Encoding class, there is an example of what you are doing here[^] (near the bottom), except that it is taking ASCII and outputting UTF-8. The princple is the same though.
Note that to use this on a stream you will need to buffer, but the process is much simpler as you already have the encoded byte array from the input buffer and theEncode
method returns a byte array for your output buffer
By looking at the comments (below) it look like the OP is having problems with html encoding. This can be decoded using this[^]
正如奥什特里(Oshtri)说的 ^ ]是您需要查看的类.
参考页;
从UTF16到UTF8到UTF16基于CString的简单转换 [将UTF8和ASCII编码的字节转换回UTF 16编码的字符串 [
As Oshtri said this[^] is the class you need to look at.
Referance pages;
UTF16 to UTF8 to UTF16 simple CString based conversion[^]
Convert UTF8 and ASCII encoded bytes back to UTF 16 encodedstring[^]
这篇关于更改字符串的编码-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文