Microsoft.Protocols.TestSuites.Common.Common.IsNullTerminatedASCIIStr C# (CSharp) Method

IsNullTerminatedASCIIStr() public static method

Check whether the byte array is null terminated ASCII string.
public static IsNullTerminatedASCIIStr ( byte bytes ) : bool
bytes byte The byte array to be checked
return bool
        public static bool IsNullTerminatedASCIIStr(byte[] bytes)
        {
            if (bytes == null)
            {
                return false;
            }

            int len = bytes.Length;

            // Check null terminate.
            if (!(bytes[len - 1] == 0x00))
            {
                return false;
            }

            for (int i = 0; i < bytes.Length; i++)
            {
                // ASCII between 0x00 and 0x7F
                if (!(bytes[i] >= 0x00 && bytes[i] <= 0x7F))
                {
                    return false;
                }
            }

            return true;
        }
Common