用ANSI读出文本,然后用UTF-8输出就可以。
解决方案 »
- 定义类,
- 以下 C 代码转换成 C# (高手进..)
- WebControls.DataGrid的问题
- 请问,我在界面上画了个字符串str(字体和字号为"MS Gothic", 10),比如str="aaa"时,如何才能得到str在界面上长度和宽度?
- 关于VS.NET里面使用SQLITE的问题
- C# 中软件运行“签名不正确”!!!急......
- 利用update触发器,怎样得到修改前和修改后的记录??
- 谁能提供几个国外的类似csdn的论坛啊?
- 请问 A窗体上有label控件,B窗体继承了A窗体,怎么去访问这个label控件?
- 调用GetOpenFileName函数的问题
- 在分发C#.Net WinForm程序时出错,
- 我们的论坛正式运行,希望大家踊跃注册.
其中Encoding.Convert方法可以满足你的需求。
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);
}
}
}
详见MSDN:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemTextEncodingClassConvertTopic.htm
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/cpref/html/frlrfSystemTextEncodingMembersTopic.htm另外,在VB中,StrConv 函数也能执行其它字符串转换。例如,它把字符串从 Unicode 码转换到 ANSI 码,或进行反向转换。有关 StrConv 函数的详细信息,请在 Visual Basic 参考帮助的索引中搜索“StrConv 函数”。