c#获取字符串长度、字节长度

 string sendData = sendTextBox.Text;    //复制发送数据
                //添加结束符
                sendData = sendData + "#$";
                //字符串发送
                if (hexadecimalSendCheckBox.IsChecked == false)
                {
                    //serial.Write(sendData);
                    byte[] arrData = System.Text.Encoding.Default.GetBytes(sendData);
                    socketUDP.SendTo(arrData,remoteEP);
                    //更新发送数据计数
                    sendBytesCount += (UInt32)sendData.Length;//获取字符串长度
                    //sendBytesCount += (UInt32)System.Text.Encoding.Default.GetBytes(sendData.ToCharArray()).Length;//获取字节长度
                    statusSendByteTextBlock.Text = sendBytesCount.ToString();

                }

猜你喜欢

转载自blog.csdn.net/yichu5074/article/details/81153152