本文整理汇总了C#中System.Text.Decoder.GetChars方法的典型用法代码示例。如果您正苦于以下问题:C# Decoder.GetChars方法的具体用法?C# Decoder.GetChars怎么用?C# Decoder.GetChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.Decoder
的用法示例。
在下文中一共展示了Decoder.GetChars方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Text;
class UnicodeEncodingExample {
public static void Main() {
Char[] chars;
Byte[] bytes = new Byte[] {
85, 0, 110, 0, 105, 0, 99, 0, 111, 0, 100, 0, 101, 0
};
Decoder uniDecoder = Encoding.Unicode.GetDecoder();
int charCount = uniDecoder.GetCharCount(bytes, 0, bytes.Length);
chars = new Char[charCount];
int charsDecodedCount = uniDecoder.GetChars(bytes, 0, bytes.Length, chars, 0);
Console.WriteLine(
"{0} characters used to decode bytes.", charsDecodedCount
);
Console.Write("Decoded chars: ");
foreach (Char c in chars) {
Console.Write("[{0}]", c);
}
Console.WriteLine();
}
}
输出:
7 characters used to decode bytes. Decoded chars: [U][n][i][c][o][d][e]
示例2: Main
//引入命名空间
using System;
using System.IO;
using System.Text;
class Class1{
static void Main(string[] args) {
byte[] byData = new byte[100];
char[] charData = new Char[100];
try {
FileStream aFile = new FileStream("practice.txt",FileMode.Open);
aFile.Seek(55,SeekOrigin.Begin);
aFile.Read(byData,0,100);
}
catch(IOException e)
{
Console.WriteLine("An IO exception has been thrown!");
Console.WriteLine(e.ToString());
Console.ReadLine();
return;
}
Decoder d = Encoding.UTF8.GetDecoder();
d.GetChars(byData, 0, byData.Length, charData, 0);
Console.WriteLine(charData);
return;
}
}