String entryinfo[][]=new String[200][2];
现在entryinfo[][]数组中有数据,我想把数组中的数据转换为一行String类型的数据
可以用,和;隔开,请问怎么实现?

解决方案 »

  1.   

    一个循环就可以了
    然后调用strng.join方法来组合每行的数组。
      

  2.   

    string sTotal = string.Empty;
    int count = 199;
    int i = 0;
    foreach(string[] temp in entryinfo)
    {
      string s = temp[0] + temp[1];
      sTotal += s+";";
      i++;
      if(i==count)
      {
         sTotal += s;
         break;
      }
    }
      

  3.   

    using System;
    using System.Collections.Generic;class Program
    {
      static void Main()
      {
        string[][] entryinfo = new string[2][];
        entryinfo[0] = new string[]{"ab","cd","efgh"};
        entryinfo[1] = new string[]{"234","eee"};
        List<string> list = new List<string>();
        for (int i = 0; i < entryinfo.GetLength(0); i++)
        {
          list.Add(string.Join(",", entryinfo[i]));
        }
        string s = string.Join(";", list.ToArray()); // 这就你想要的
        Console.WriteLine(s);            // 输出:ab,cd,efgh;234,eee
      }
    }
      

  4.   

    using System;
    using System.Collections.Generic;class Program
    {
      static void Main()
      {
        string[][] entryinfo = new string[2][];
        entryinfo[0] = new string[]{"ab","cd","efgh"};
        entryinfo[1] = new string[]{"234","eee"};
        List<string> list = new List<string>();
        for (int i = 0; i < entryinfo.GetLength(0); i++)
        {
          list.Add(string.Join(",", entryinfo[i]));
        }
        string s = string.Join(";", list.ToArray()); // 这就你想要的
        Console.WriteLine(s);            // 输出:ab,cd,efgh;234,eee
      }
    }
    \\\\\\\\\\\\\\\\
     正解!
      

  5.   

     string[][] fn = new string[12][];
        protected void Page_Load(object sender, EventArgs e)
        {
            this.a();
        }
        public void a() 
        {      
           fn[0] = new string[] { "aa", "aaa", "aaaa" };
           fn[1] = new string[] { "bb", "bbb", "bbbb" };       string ss = "";
           string[] arr = null;
           for (int i = 0; i < fn.Length;i++ ) 
           {          
               arr = fn[i];
               if (fn[i] != null)
               {
                   for (int j = 0; j < arr.Length; j++)
                   {
                       ss += arr[j] + ",";
                   }
               }
           }
           ss =ss.Substring(0,ss.Length - 1); 
        }  
      

  6.   

    using System;
    using System.Collections.Generic;class Program
    {
      static void Main()
      {
        // 构造一个输入:
        string[][] entryinfo = new string[][]
        {
          new string[]{ "1:","ab","cd","efgh" },
          new string[]{ "2:","34","eee"       },
          new string[]{                       },
          new string[]{ "4:","OK"             },
        };    // 以下是我的解答:
        List<string> list = new List<string>();
        foreach (string[] ss in entryinfo)
        {
          list.Add(string.Join(",", ss));
        }
        string s = string.Join(";", list.ToArray());  // 这就你想要的
        Console.WriteLine(s); // 输出:1:,ab,cd,efgh;2:,34,eee;;4:,OK
      }
    }
      

  7.   


    using System;
    using System.Collections.Generic;class Program
    {
      static void Main()
      {
        // 构造一个输入:
        string[][] entryinfo = new string[][]
        {
          new string[]{ "1:","ab","cd","efgh" },
          new string[]{ "2:","34","eee"       },
          new string[]{                       },
          new string[]{ "4:","OK"             },
        };    // 以下是我的解答:
        List<string> list = new List<string>();
        foreach (string[] ss in entryinfo)
        {
          list.Add(string.Join(",", ss));
        }
        string s = string.Join(";", list.ToArray());  // 这就你想要的
        Console.WriteLine(s); // 输出:1:,ab,cd,efgh;2:,34,eee;;4:,OK
      }
    }这个方法不错