[英]Appending string to byte array for transmission over TCP
I need to append some text/string to a byte array, for transmission over TCP. 我需要将一些文本/字符串附加到字节数组,以便通过TCP传输。
I tried: 我试过了:
byte[] msg1 = Encoding.UTF8.GetBytes("\u00C3\u00C4\u00C5\u00C3\u00A2\u00A1sometext");
but this doesn't get me the right result when sent to TCP. 但这在发送到TCP时无法得到正确的结果。
Then I tried with the following: 然后我尝试了以下方法:
byte[] msg2 = new byte[] { 0xC3, 0xC4, 0xC5, 0xC3, 0XA2, 0xA1};
Now when sending msg over to TCP, it's the correct result. 现在,将msg发送到TCP时,它是正确的结果。 But how do I add
sometext
to 'msg2'
但是我如何在
'msg2'
添加sometext
'msg2'
I used System.Buffer.BlockCopy
我用了
System.Buffer.BlockCopy
byte[] rv = new byte[msg.Length + test.Length];
System.Buffer.BlockCopy(msg, 0, rv, 0, msg.Length);
System.Buffer.BlockCopy(test, 0, rv, msg.Length, test.Length);
Anyone's got a better way please add. 任何人都有更好的方法,请补充。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.