Encoding Class represents a character encoding.
using System;
using System.Text;
class ConvertExampleClass
{
static void Main()
{
string unicodeString = "Pi(\u03a0)";
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);
Console.WriteLine("Original string: {0}", unicodeString);
Console.WriteLine("Ascii converted string: {0}", asciiString);
}
}
Related examples in the same category