当前位置: 首页>>代码示例>>C#>>正文


C# UnicodeEncoding.GetDecoder方法代码示例

本文整理汇总了C#中System.Text.UnicodeEncoding.GetDecoder方法的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding.GetDecoder方法的具体用法?C# UnicodeEncoding.GetDecoder怎么用?C# UnicodeEncoding.GetDecoder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.UnicodeEncoding的用法示例。


在下文中一共展示了UnicodeEncoding.GetDecoder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PosTest1

 public void PosTest1()
 {
     Char[] srcChars = GetCharArray(10);
     Char[] desChars = new Char[10];
     Byte[] bytes = new Byte[20];
     int buffer;
     int outChars;
     bool completed;
     UnicodeEncoding uEncoding = new UnicodeEncoding();
     int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0);
     bool expectedValue = true;
     bool actualValue = true;
     Decoder dC = uEncoding.GetDecoder();
     dC.Convert(bytes, 0, 20, desChars, 0, 10, true, out buffer, out outChars, out completed);
     if (completed)
     {
         for (int i = 0; i < 10; i++)
         {
             actualValue = actualValue & (desChars[i] == srcChars[i]);
         }
     }
     Assert.Equal(expectedValue, actualValue);
 }
开发者ID:jmhardison,项目名称:corefx,代码行数:23,代码来源:UnicodeEncodingGetDecoder.cs

示例2: UsingMemoryStream

        private void UsingMemoryStream()
        {
            System.Threading.Thread.Sleep(5000);
            Console.WriteLine("Memory Stream Example");
            int count;
            byte[] byteArray;
            char[] charArray;

            UnicodeEncoding uniEncoding = new UnicodeEncoding();

            byte[] firstString = uniEncoding.GetBytes("Invalid file path character are: ");
            byte[] secondString = uniEncoding.GetBytes(Path.GetInvalidFileNameChars());

            using (MemoryStream memStream = new MemoryStream(100))
            {
                memStream.Write(firstString, 0, firstString.Length);

                count = 0;
                while(count < secondString.Length)
                {
                    memStream.WriteByte(secondString[count++]);
                }

                Console.WriteLine("Capacity = {0}, Length = {1}, Position = {2}",
                    memStream.Capacity,
                    memStream.Length,
                    memStream.Position);

                memStream.Seek(0, SeekOrigin.Begin);

                byteArray = new byte[memStream.Length];
                count = memStream.Read(byteArray, 0, 20);

                while(count<memStream.Length)
                {
                    byteArray[count++] = Convert.ToByte(memStream.ReadByte());
                }

                charArray = new char[uniEncoding.GetCharCount(byteArray,0,count)];
                uniEncoding.GetDecoder().GetChars(byteArray, 0, count, charArray, 0);
                Console.WriteLine(charArray);

            }
        }
开发者ID:mayankaggarwal,项目名称:MyConcepts,代码行数:44,代码来源:WorkingWithStreams.cs


注:本文中的System.Text.UnicodeEncoding.GetDecoder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。