例如:textbox输入123456 ;在byte里面为{0x12,0x34,0x56}

解决方案 »

  1.   

    先两个两个SubString,
    再用Byte.Parse()
      

  2.   


                string str = "123456";
                var bt = Regex.Matches(str, @"[a-fA-F0-9]{2}").Cast<Match>().Select(t => (byte)Convert.ToInt32(t.Value, 16)).ToArray();
      

  3.   

    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();
      

  4.   

    至于么,都成日经贴了
    移步:
    http://bbs.csdn.net/topics/390283055
      

  5.   


    Regex和Match不能用,using用什么?
      

  6.   

    http://www.cnblogs.com/Mainz/archive/2008/04/09/String_Byte_Array_Convert_CSharp.html
      

  7.   

    using System.Text.RegularExpressions;
      

  8.   

                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);
                }
               
      

  9.   

    最近好像很少有一点工作经验的人上csdn发帖了。