rtbyte[] bytes = {....};
string str = BitConverter.ToString( bytes );这样返回的str是“xx-xx-xx-xx-xx...”这种格式的,请问有没有什么比较正规(
就是不用replace之类的方法)的方法让返回的字符串没有中间的“-”?
拜谢!

解决方案 »

  1.   

    内核代码已经写死了:
    public static string ToString(byte[] value, int startIndex, int length)
    {
        if (value == null)
        {
            throw new ArgumentNullException("byteArray");
        }
        int num = value.Length;
        if ((startIndex < 0) || ((startIndex >= num) && (startIndex > 0)))
        {
            throw new ArgumentOutOfRangeException("startIndex", Environment.GetResourceString("ArgumentOutOfRange_StartIndex"));
        }
        int num2 = length;
        if (num2 < 0)
        {
            throw new ArgumentOutOfRangeException("length", Environment.GetResourceString("ArgumentOutOfRange_GenericPositive"));
        }
        if (startIndex > (num - num2))
        {
            throw new ArgumentException(Environment.GetResourceString("Arg_ArrayPlusOffTooSmall"));
        }
        if (num2 == 0)
        {
            return string.Empty;
        }
        char[] chArray = new char[num2 * 3];
        int index = 0;
        int num4 = startIndex;
        for (index = 0; index < (num2 * 3); index += 3)
        {
            byte num5 = value[num4++];
            chArray[index] = GetHexValue(num5 / 0x10);
            chArray[index + 1] = GetHexValue(num5 % 0x10);
            chArray[index + 2] = '-';
        }
        return new string(chArray, 0, chArray.Length - 1);
    }        chArray[index + 2] = '-';
      

  2.   

    不用替换,没想到太好的办法
                byte[] bytes = new byte[] { 0x10, 0xef };
                StringBuilder sb = new StringBuilder();
                foreach (byte b in bytes)
                    sb.AppendFormat("{0:x2}", b);
                string result = sb.ToString().ToUpper();
      

  3.   

    .Replace("-", null);或者自己把上面的代码改改写个自己的方法
      

  4.   

    string str = BitConverter.ToString( bytes).Replace("-","");  //over