c# byte字节数组与string字符串之间的转换

来源:互联网 发布:mac qq邮箱 pop服务器 编辑:程序博客网 时间:2024/04/30 21:20

            字符串转换为字节数组:

           string str = richTextBox2.Text.Trim()+"\r\n";

            byte[] buffer = Encoding.UTF8.GetBytes(str);

            socketSend.Send(buffer);


           字节数组转换为字符串:

           byte[] buffer = new byte[1024 * 1024 * 2];

           client_socket.Receive(buffer);

           string str = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

           MessageBox.Show(string);

0 0