如果我有这样的字符串数组:
string[] str = new string[]{"abc", "bacd", "pacds"};
然后我需要输出如下使用LINQ:
输出:abc,abcd,acdps
答案 0 :(得分:1)
您可以使用String.Concat(st.OrderBy(c => c))
按字符顺序排序字符串。
str.ToList().ForEach((val) => {
val = String.Concat(val.OrderBy(c => c));
});
答案 1 :(得分:0)
这应该是你想要的:
string[] str = new string[] { "abc", "bacd", "pacds" };
var result = str.Select(c => String.Concat(c.OrderBy(d => d)));
result
为IEnumerable<string>
,但如果您希望将结果添加到字符串数组中,请添加.ToArray()
:
var result = str.Select(c => String.Concat(c.OrderBy(d => d))).ToArray();
结果:
答案 2 :(得分:0)
str.Select(x => x.ToCharArray().OrderBy(c => c).Aggregate("", (s,c)=>s+c))
答案 3 :(得分:0)
this just to change the array strings into chars-ordered ones
static void orderChars(string[] str)
{
for (int i = 0; i < str.Length; i++)
str[i] = new string(str[i].OrderBy(c => c).ToArray());
}
答案 4 :(得分:-1)
正如bassfader评论的那样,显示你的代码并说出你被困的地方,无论如何我们都可以引导你..
你可以这样写,
string [] a = new string [] {&#34;印度尼西亚&#34;&#34;韩国&#34;&#34;日本&#34;&#34;英语&#34;&#34;德国&#34;};
var sort = from s in order by s select s;