public static byte[] smethod_2(string string_0)
        {
            byte[] array = new byte[string_0.Length / 2];
            for (int i = 0; i < string_0.Length; i += 2)
            {
                array[i / 2] = Convert.ToByte(string_0.Substring(i, 2), 16);
            }
            return array;
        }
这个是字符串转数组
怎么写数组转字符串方法

解决方案 »

  1.   

    string s = string.Join("", array.Select((x, i) => new { x, i}).GroupBy(x => x.i / 2).Select(x => x.First().x * 256 + x.Last().x).Select(x => x.ToString(X2)));
      

  2.   

        string s = string.Join("", bytes05.Select((x, i) => new { x, i }).GroupBy(x => x.i / 2).Select(x => x.First().x * 256 + x.Last().x).Select(x => x.ToString("x2")));是这样写吗
      

  3.   

    如果你不想用linq,用循环也是可以的。StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes05.GetLength(0) / 2; i++)
    {
        int x = bytes05[i * 2] * 256 + bytes05[i * 2 + 1];
        sb.Append(x.ToString("X2"));
    }
    string result = sb.ToString();
      

  4.   

    这个是本来的
    字符 string str1="78dad33af9deb1bad6fc4f53b176efdf770ef33c1a65620fcb451f3d76a949c54ff1e25c000eef1023";byte[] bys=smethod_2(str1);这个是方法
    public static byte[] smethod_2(string string_0)
       {
       byte[] array = new byte[string_0.Length / 2];
       for (int i = 0; i < string_0.Length; i += 2)
       {
       array[i / 2] = Convert.ToByte(string_0.Substring(i, 2), 16);
       }
       return array;
       }
    我想求已知的数组bys  怎么样求str1
      

  5.   

    怎么安你的方法求出会不同。2AC9EF417B7D37FC82732B8DFDEE409E48811C5DC31E5BC5C6D282244E21D19D
      

  6.   

    怎么不是78dad33af9deb1bad6fc4f53b176efdf770ef33c1a65620fcb451f3d76a949c54ff1e25c000eef1023
      

  7.   

    哦,不好意思,我写反了string s = string.Join("", bytes05.Select(x => x.ToString("x2"));
      

  8.   

    老师,为什么编回去还是
    2ac9ef417b7d37fc82732b8dfdee409e48811c5dc31e5bc5c6d282244e21d19d不是这个呢
    78dad33af9deb1bad6fc4f53b176efdf770ef33c1a65620fcb451f3d76a949c5
    4ff1e25c000eef1023
      

  9.   

    奇怪,我这里正常啊using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str1="78dad33af9deb1bad6fc4f53b176efdf770ef33c1a65620fcb451f3d76a949c54ff1e25c000eef1023";
                var bytes05 = smethod_2(str1);
                string s = string.Join("", bytes05.Select(x => x.ToString("x2")));
                Console.WriteLine(s);
            }
            public static byte[] smethod_2(string string_0)
            {
                byte[] array = new byte[string_0.Length / 2];
                for (int i = 0; i < string_0.Length; i += 2)
                {
                    array[i / 2] = Convert.ToByte(string_0.Substring(i, 2), 16);
                }
                return array;
            }
        }
    }
      

  10.   

    这事太奇怪的,我的是用WINFORM 写的VS2010
      

  11.   

        public static byte[] smethod_0(byte[] byte_0)
            {
                byte[] result;
                try
                {
                    MemoryStream memoryStream = new MemoryStream();
                    Stream stream = new ZOutputStream(memoryStream);
                    stream.Write(byte_0, 0, byte_0.Length);
                    stream.Close();
                    byte[] array = memoryStream.ToArray();
                    memoryStream.Flush();
                    memoryStream.Close();
                    result = array;
                }
                catch
                {
                    result = null;
                }
                return result;
            }
    原来被压缩的
      

  12.   

        byte[] byte_ = smethod_2(textBox1.Text);
                byte_ = smethod_0(byte_);
       public static byte[] smethod_0(byte[] byte_0)
            {
                byte[] result;
                try
                {
                    MemoryStream memoryStream = new MemoryStream();
                    Stream stream = new ZOutputStream(memoryStream);
                    stream.Write(byte_0, 0, byte_0.Length);
                    stream.Close();
                    byte[] array = memoryStream.ToArray();
                    memoryStream.Flush();
                    memoryStream.Close();
                    result = array;
                }
                catch
                {
                    result = null;
                }
                return result;
            }