BonCodeAJP13Namespace.BonCodeAJP13Packet.SetString C# (CSharp) Method

SetString() protected static method

Set the String value in the array starting from the position Pos String will be transmitted prefixed by length in bytes and terminated by zero byte
protected static SetString ( byte Data, string Value, int Pos, int StrLength ) : int
Data byte
Value string
Pos int
StrLength int
return int
        protected static int SetString(byte[] Data, string Value, int Pos, int StrLength)
        {
            byte[] ValueData = new byte[Value.Length + 2];
            SetUInt16(ValueData, (UInt16)Value.Length, 0); //first set the length of the string
            ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

            byte[] temp = new byte[Value.Length];
            temp = encoding.GetBytes(Value);

            Array.Copy(temp, 0, ValueData, 2, temp.Length);
            Array.Copy(ValueData, 0, Data, Pos, ValueData.Length); //terminate the string with zero
            return Pos + Value.Length + 2;
        }