Отправить все байты из richTextBox - PullRequest
0 голосов
/ 19 февраля 2020

У меня есть richTextBox и байтовый массив.

byte[] message = Encoding.Default.GetBytes(richTextBox1.Text);

byte[] bytesToSend = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (MESSAGE SHOULD BE HERE), 0x00 };

Как я могу это сделать?

1 Ответ

2 голосов
/ 19 февраля 2020
    static byte[] SomeMethod(string value, Encoding encoding)
    {
        // create an array with the space needed for the value and the zeros
        var bytes = new byte[encoding.GetByteCount(value) + 9];
        // encode the data into the array starting at position 8
        encoding.GetBytes(value, 0, value.Length, bytes, 8);
        // and we're done
        return bytes;
    }
    var bytesToSend = SomeMethod(richTextBox1.Text, Encoding.Default);
    // (but probably not Encoding.Default - that is almost always wrong)
...