更改字符串的编码-C# [英] Change encoding of a string - C#

查看:249
本文介绍了更改字符串的编码-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何更改字符串编码.

在此先感谢
关于

I want to know how can i change an string encoding.

Thanks in advance
Regards

推荐答案

本质上是将原始字符串转换为字节数组,然后使用所需的编码将字节数组转换回字符串的过程.为此,您使用Encoding类,这里有一个您正在做的示例 [
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 the Encode 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆