C#,用于utf-8,gb2312互相转换代码,谢谢
解决方案 »
- ADO.NET,请问 DataTable.Columns.Add(DataColumn)方法
- 怎样实现在选中checkBox后音乐循环播放,菜鸟向高手求助,下面是已有代码
- C# 设备应用程序 无法由MS VS2005版本加载到MS VS2008版本:未安装该项目应用程序
- 如何创建调用带参数的方法的进程?
- 问个代码复用的问题。100分。
- 请帮看看SQL语句有无错误
- webBrowser如何获得iframe的内容
- Windows服务程序使用Softing OPC Toolbox connect OPC Server
- !急请教,采用后台编码,如何递交参数
- 如果在winform中加入类似vb6中的webbrowser控件?C#中有吗?
- 计时器中使用方法获取客户ip时遇到的问题,,请高手指教.
- 新手进阶:有关数组的应用
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);
}
}
}