c# 如何使textbox string转型为byte 例如:textbox输入123456 ;在byte里面为{0x12,0x34,0x56} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先两个两个SubString,再用Byte.Parse() string str = "123456"; var bt = Regex.Matches(str, @"[a-fA-F0-9]{2}").Cast<Match>().Select(t => (byte)Convert.ToInt32(t.Value, 16)).ToArray(); string str = "112233";List<byte> bt = new List<byte>(); foreach (Match m in Regex.Matches(str, @"[a-fA-F0-9]{2}")) { bt.Add((byte)Convert.ToInt32(m.Value, 16)); }byte[] ary= bt.ToArray(); 至于么,都成日经贴了移步:http://bbs.csdn.net/topics/390283055 Regex和Match不能用,using用什么? http://www.cnblogs.com/Mainz/archive/2008/04/09/String_Byte_Array_Convert_CSharp.html using System.Text.RegularExpressions; string aa= textBox3.Text;//123456 byte[] bytes = new byte[aa.Length / 2]; for (int i = 0; i < bytes.Length; i++) { bytes[i] = Convert.ToByte(aa.Substring(i * 2, 2), 16); } 最近好像很少有一点工作经验的人上csdn发帖了。 C#调用c++ DLL 小弟初学者,有个疑问。。还望指点。(我都佩服我孜孜不倦的精神了) 执行外部程序 刚入门,那位大虾能帮小弟解释一下这句代码呢? 如何把数组中的空值去掉 我在98系统中装了.NETFrame,我可以运行程序,但是出现这样的错误. 谁使用的是VS2005版的?有问题急需请教,谢谢 .net后台生成Html分页功能实现 使用GetWindowText获取不到窗口标题 VC++.net事件 大家讨论下如何提高程序效率 帮忙一下,急
再用Byte.Parse()
string str = "123456";
var bt = Regex.Matches(str, @"[a-fA-F0-9]{2}").Cast<Match>().Select(t => (byte)Convert.ToInt32(t.Value, 16)).ToArray();
List<byte> bt = new List<byte>();
foreach (Match m in Regex.Matches(str, @"[a-fA-F0-9]{2}"))
{
bt.Add((byte)Convert.ToInt32(m.Value, 16));
}
byte[] ary= bt.ToArray();
移步:
http://bbs.csdn.net/topics/390283055
Regex和Match不能用,using用什么?
byte[] bytes = new byte[aa.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(aa.Substring(i * 2, 2), 16);
}