C#中怎么在string和byte[]之间做转换? string strVal = "HelloWorld";我想将这个strVal转换成byte[]类型,不知道在C#中怎么弄? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 byte[] buffer = Encoding.ASCII.GetBytes("HelloWorld"); string str = "123"; byte[] b = new byte[str.Length]; for (int i = 0; i < str.Length; i++) { b[i] = Convert.ToByte(str.Substring(i, 1)); }有点笨的方法 byte[] p = strVal.getbytes(); byte[] byVal = strVal.getbytes(); byte[] b = Encoding.Default.GetBytes(strVal);用這個吧 strVal.getbytes(); 有这个方法吗?怀疑。 string --> byte[]byte[] b[] = System.Text.Encoding.ASCII.GetBytes(string);-------------------------------------------------------------------------string --> bytebyte b = Convert.ToByte(string);-------------------------------------------------------------------------byte[] --> stringstring s = Encoding.ASCII.GetString(bytes, 0, nBytesSize); 关于c#的时间控件问题求助 在Net的数据访问层中怎样将异常打印出来 紧急求助,关于全局变量在不同Form间的传递问题!! 一个sql函数转换为access中的语句 Beginning+C#+Objects中文版电子书!希望有的朋友提供一份! 能否用SQL语句检索DataSet数据集并返回结果? 为何用HttpWebRequest下载页面时总是到中途停在那里 怎样让一个按钮变为灰色,就是禁用状态? 请教高手个问题 binaryWriter 急求一winform下的日历控件:可以显示分秒 C#如何取得客户端外网IP地址????????????????????
byte[] b = new byte[str.Length];
for (int i = 0; i < str.Length; i++)
{
b[i] = Convert.ToByte(str.Substring(i, 1));
}
有点笨的方法
用這個吧
有这个方法吗?
怀疑。
byte[] b[] = System.Text.Encoding.ASCII.GetBytes(string);
-------------------------------------------------------------------------
string --> byte
byte b = Convert.ToByte(string);
-------------------------------------------------------------------------
byte[] --> string
string s = Encoding.ASCII.GetString(bytes, 0, nBytesSize);