0

string[ ][ ]例如,我有一个{{a,b}{c,d}}。如何将其转换为字符串或使用拆分方法string[ ][ ]正确显示?

     string[][] result;
     result = test.AnagramsFinder(inputArray); //which returns string[][]
     string value = string.Join(";",result); // this line does not work for me
     Label1.Text = value ;

仅适用于string[ ],但不是string[ ][ ]

4

5 回答 5

3

对于"a, b, c, d"结果:

 string value = string.Join(", ", result.SelectMany(a => a));

对于"a, b; c, d"选项:

string value = string.Join("; ", result.Select(a => string.Join(", ", a))) ;
于 2013-10-17T13:02:56.543 回答
1

即使我无法遵循您的用例:

using System.Linq;

string[][] result;
result = test.AnagramsFinder(inputArray); //which returns string[][]
string value = string.Join(";",result.SelectMany(x=> x)); 
Label1.Text = value ;
于 2013-10-17T13:02:06.293 回答
1
using System.Linq;

string value = string.Join(";",result.Selectmany(x => x);
于 2013-10-17T13:03:48.763 回答
0

要实现数组的良好字符串表示,您可以使用以下代码:

Label1.Text = result
    .Select(item => item.Aggregate((left,right) => left + "," + right))
    .Aggregate((left , right) => left + "|" + right);

对于给定的输入数组

var input = new[] {new[]{"a", "b"}, new[]{"c", "d"}};

这提供了结果

a,b|c,d
于 2013-10-17T13:13:20.733 回答
0
String.Join(";", result.Select(a => String.Join(",", a)).ToArray());

输出:

A B C D

于 2013-10-17T13:35:18.993 回答