本文整理匯總了C#中System.Text.UTF7Encoding類的典型用法代碼示例。如果您正苦於以下問題:C# UTF7Encoding類的具體用法?C# UTF7Encoding怎麽用?C# UTF7Encoding使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UTF7Encoding類屬於System.Text命名空間,在下文中一共展示了UTF7Encoding類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Text;
class UTF7EncodingExample {
public static void Main() {
// Create a UTF-7 encoding.
UTF7Encoding utf7 = new UTF7Encoding();
// A Unicode string with two characters outside a 7-bit code range.
String unicodeString =
"This Unicode string contains two characters " +
"with codes outside a 7-bit code range, " +
"Pi (\u03a0) and Sigma (\u03a3).";
Console.WriteLine("Original string:");
Console.WriteLine(unicodeString);
// Encode the string.
Byte[] encodedBytes = utf7.GetBytes(unicodeString);
Console.WriteLine();
Console.WriteLine("Encoded bytes:");
foreach (Byte b in encodedBytes) {
Console.Write("[{0}]", b);
}
Console.WriteLine();
// Decode bytes back to string.
// Notice Pi and Sigma characters are still present.
String decodedString = utf7.GetString(encodedBytes);
Console.WriteLine();
Console.WriteLine("Decoded bytes:");
Console.WriteLine(decodedString);
}
}