以 Common Language Runtime 為目標的應用程式會使用編碼方式,將字元表示從原生字元配置對應至其他配置。應用程式會使用編碼方式,將字元從非原生配置對應至原生配置。下表會列出在 System.Text 命名空間中最常用來將字元編碼和解碼的類別。
Dim MyString As String = "Encoding String."
Dim AE As New ASCIIEncoding()
Dim ByteArray As Byte() = AE.GetBytes(MyString)
Dim x as Integer
For x = 0 To ByteArray.Length - 1
Console.Write("{0} ", ByteArray(x))
Next
string MyString = "Encoding String.";
ASCIIEncoding AE = new ASCIIEncoding();
byte[] ByteArray = AE.GetBytes(MyString);
for(int x = 0;x <= ByteArray.Length - 1; x++)
{
Console.Write("{0} ", ByteArray[x]);
}
69 110 99 111 100 105 110 103 32 83 116 114 105 110 103 46
Dim AE As New ASCIIEncoding()
Dim ByteArray As Byte() = { 69, 110, 99, 111, 100, 105, 110, 103, 32, 83, 116, 114, 105, 110, 103, 46 }
Dim CharArray As Char() = AE.GetChars(ByteArray)
Dim x As Integer
For x = 0 To CharArray.Length - 1
Console.Write(CharArray(x))
Next
ASCIIEncoding AE = new ASCIIEncoding();
byte[] ByteArray = { 69, 110, 99, 111, 100, 105, 110, 103, 32, 83, 116, 114, 105, 110, 103, 46 };
char[] CharArray = AE.GetChars(ByteArray);
for(int x = 0;x <= CharArray.Length - 1; x++)
{
Console.Write(CharArray[x]);
}