本文整理汇总了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);
}
}