从 richTextBox 发送所有字节

Send all bytes from richTextBox

我有一个 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 };

我该怎么做?

    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)