I got a string[ ][ ]
, for example {{a,b}{c,d}}
. How could convert it to string or using split method to display string[ ][ ]
properly?
string[][] result;
result = test.AnagramsFinder(inputArray); //which returns string[][]
string value = string.Join(";",result); // this line does not work for me
Label1.Text = value ;
is only for string[ ]
, but not string[ ][ ]
.
For an "a, b, c, d" result:
string value = string.Join(", ", result.SelectMany(a => a));
and for the "a, b; c, d" option:
string value = string.Join("; ", result.Select(a => string.Join(", ", a))) ;
Even though I cannot follow your usecase for this:
using System.Linq;
string[][] result;
result = test.AnagramsFinder(inputArray); //which returns string[][]
string value = string.Join(";",result.SelectMany(x=> x));
Label1.Text = value ;
using System.Linq;
string value = string.Join(";",result.Selectmany(x => x);
To achieve a nice string representation of your array you can use the following code:
Label1.Text = result
.Select(item => item.Aggregate((left,right) => left + "," + right))
.Aggregate((left , right) => left + "|" + right);
for a give input array
var input = new[] {new[]{"a", "b"}, new[]{"c", "d"}};
this delivers the result
a,b|c,d
String.Join(";", result.Select(a => String.Join(",", a)).ToArray());
Output:
a,b;c,d
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.