Renci.SshNet.Common.ASCIIEncoding.GetChars C# (CSharp) Method

GetChars() public method

Decodes a sequence of bytes from the specified byte array into the specified character array.
is null.-or- is null. or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . does not have enough capacity from to the end of the array to accommodate the resulting characters.
public GetChars ( byte bytes, int byteIndex, int byteCount, char chars, int charIndex ) : int
bytes byte The byte array containing the sequence of bytes to decode.
byteIndex int The index of the first byte to decode.
byteCount int The number of bytes to decode.
chars char The character array to contain the resulting set of characters.
charIndex int The index at which to start writing the resulting set of characters.
return int
        public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
        {
            for (var i = 0; i < byteCount; i++)
            {
                var b = bytes[i + byteIndex];
                char ch;

                if (b > 127)
                {
                    ch = _fallbackChar;
                }
                else 
                {
                    ch = ByteToChar[b];
                }

                chars[i + charIndex] = ch;
            }
            return byteCount;
        }

Usage Example

示例#1
0
 public void GetCharsTest()
 {
     ASCIIEncoding target = new ASCIIEncoding(); // TODO: Initialize to an appropriate value
     byte[] bytes = null; // TODO: Initialize to an appropriate value
     int byteIndex = 0; // TODO: Initialize to an appropriate value
     int byteCount = 0; // TODO: Initialize to an appropriate value
     char[] chars = null; // TODO: Initialize to an appropriate value
     int charIndex = 0; // TODO: Initialize to an appropriate value
     int expected = 0; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.GetChars(bytes, byteIndex, byteCount, chars, charIndex);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }