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


C# UnicodeEncoding.GetCharCount方法代码示例

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


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

示例1: Start

    // Use this for initialization
    private void Start()
    {
        int count;
        byte[] byteArray;
        char[] charArray;
        UnicodeEncoding uniEncoding = new UnicodeEncoding();

        // Create the data to write to the stream. 
        byte[] firstString = uniEncoding.GetBytes(
            "Invalid file path characters are: ");
        byte[] secondString = uniEncoding.GetBytes(
            "123456789");

        using (MemoryStream memStream = new MemoryStream(100))
        {
            // Write the first string to the stream.
            memStream.Write(firstString, 0, firstString.Length);

            // Write the second string to the stream, byte by byte.
            count = 0;
            while (count < secondString.Length)
            {
                memStream.WriteByte(secondString[count++]);
            }

            // Write the stream properties to the console.
            Debug.Log(String.Format(
                "Capacity = {0}, Length = {1}, Position = {2}\n",
                memStream.Capacity.ToString(),
                memStream.Length.ToString(),
                memStream.Position.ToString()));

            // Set the position to the beginning of the stream.
            memStream.Seek(0, SeekOrigin.Begin);

            // Read the first 20 bytes from the stream.
            byteArray = new byte[memStream.Length];
            count = memStream.Read(byteArray, 0, 20);

            // Read the remaining bytes, byte by byte. 
            while (count < memStream.Length)
            {
                byteArray[count++] =
                    Convert.ToByte(memStream.ReadByte());
            }

            // Decode the byte array into a char array 
            // and write it to the console.
            charArray = new char[uniEncoding.GetCharCount(
                byteArray, 0, count)];
            uniEncoding.GetDecoder().GetChars(
                byteArray, 0, count, charArray, 0);
            Debug.Log(charArray);
        }
    }
开发者ID:benbon,项目名称:qjsbunitynew,代码行数:56,代码来源:StreamTest.cs

示例2: PosTest4

        public void PosTest4()
        {
            Char[] chars = GetCharArray(10);
            Byte[] bytes = new Byte[20];
            UnicodeEncoding uEncoding = new UnicodeEncoding();
            int byteCount = uEncoding.GetBytes(chars, 0, 10, bytes, 0);
            int actualValue;

            actualValue = uEncoding.GetCharCount(bytes, 20, 0);
            Assert.Equal(0, actualValue);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:11,代码来源:UnicodeEncodingGetCharCount.cs

示例3: NegTest1

 public void NegTest1()
 {
     Char[] chars = GetCharArray(10);
     Byte[] bytes = new Byte[20];
     UnicodeEncoding uEncoding = new UnicodeEncoding();
     int byteCount = uEncoding.GetBytes(chars, 0, 10, bytes, 0);
     int actualValue;
     Assert.Throws<ArgumentNullException>(() =>
     {
         actualValue = uEncoding.GetCharCount(null, 0, 0);
     });
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:12,代码来源:UnicodeEncodingGetCharCount.cs

示例4: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        Char[] chars = GetCharArray(10);
        Byte[] bytes = new Byte[20];

        UnicodeEncoding uEncoding = new UnicodeEncoding();
        int byteCount = uEncoding.GetBytes(chars,0,10,bytes,0);

        int expectedValue = 10;

        int actualValue;

        TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method.");
        try
        {
            actualValue = uEncoding.GetCharCount(bytes, 0, 20);

            if (expectedValue != actualValue)
            {
                TestLibrary.TestFramework.LogError("001", "ExpectedValue(" + expectedValue + ") !=ActualValue(" + actualValue + ")" + " when Chars is:" + ToString(chars));
                retVal = false;
            }

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception:" + e + " when Chars is:" + ToString(chars));
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:33,代码来源:unicodeencodinggetcharcount.cs

示例5: NegTest5

    public bool NegTest5()
    {
        bool retVal = true;

        Char[] chars = GetCharArray(10);
        Byte[] bytes = new Byte[20];

        UnicodeEncoding uEncoding = new UnicodeEncoding();
        int byteCount = uEncoding.GetBytes(chars, 0, 10, bytes, 0);

        int actualValue;

        TestLibrary.TestFramework.BeginScenario("NegTest5:Invoke the method and set byteCount as 21");
        try
        {
            actualValue = uEncoding.GetCharCount(bytes, 0, 21);

            TestLibrary.TestFramework.LogError("015", "No ArgumentOutOfRangeException throw out expected.");
            retVal = false;
        }
        catch (ArgumentOutOfRangeException)
        {

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("016", "Unexpected exception:" + e);
            retVal = false;
        }
        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:31,代码来源:unicodeencodinggetcharcount.cs


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