.NET编码常用转换
来源:互联网 发布:创业软件股票解禁 编辑:程序博客网 时间:2024/05/16 11:47
bytes=System.Text.Encoding.Unicode.GetBytes(str)
作用:把str的载体作Unicode->Unicode的编码转换--也就是没有对载体作任何的转换。因些使用此函数可以得代表该String载体的字节数组。
str=System.Text.Encoding.Unicode.GetString(bytes)
作用:对字节数组作Unicode->Unicode的编码转换--即没有转换,把经过转换后的字节数组作为str的载体。
bytes=System.Text.Encoding.Utf8.GetBytes(str)
作用:把str的载体作Utf8->Unicode的编码转换。返回的是经过转换后的字符数组
str=System.Text.Encoding.Utf8.GetString(bytes)
作用:对字节数组作Gb2312->Unicode的编码转换,把经过转换后的字节数组作为str的载体。
bytes=System.Text.Encoding.GetEncoding("GB2312").GetBytes(str)
作用:把str的载体作Gb2312->Unicode的编码转换。返回的是经过转换后的字符数组
str=System.Text.Encoding.GetEncoding("GB2312").GetString(bytes)
作用:对字节数组作Gb2312->Unicode的编码转换,把经过转换后的字节数组作为str的载体。
如此类推
bytes=System.Text.Encoding.GetEncoding("XXX").GetBytes(str)
作用:把str的载体作XXX->Unicode的编码转换。返回的是经过转换后的字符数组
str=System.Text.Encoding.GetEncoding("XXX").GetString(bytes)
作用:对字节数组作XXX->Unicode的编码转换,把经过转换后的字节数组作为str的载体。
C#将字符串从一种编码转换为另一种编码:
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);
}
}
}
- .NET编码常用转换
- 常用编码转换
- 字符串常用编码转换
- 常用字符编码转换函数
- MFC常用字符编码转换
- .net常用的编码技巧
- 计算机常用编码及转换方法介绍
- 常用字符串编码转换的函数
- 常用的字符编码转换集合
- iOS 字符串常用编码互相转换
- 转换CSS中常用的颜色编码
- asp.net把utf-8编码转换为gb2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- Asp.net把UTF-8编码转换为GB2312编码
- CUDA: Threading的Block和Grid的設定與 Warp
- Android sd卡使用解说
- 关于GCD的8题
- SQLServer的数据类型
- 二进制和XML两种网络数据格式的比较
- .NET编码常用转换
- oracle 查询出一段时间内连续时间间隔的记录集
- Android WebView 技巧
- Eclipse 快捷键使用过程中遇到的两個小问题
- Android4.3 Bluetooth开篇
- java数据结构_笔记(4)_图
- 工作流的待审批信息
- HDU 3697 Selecting courses (贪心)
- hdu 1671 Phone List