Is there a simple way that I can sort characters in a string in alphabetical order

后端 未结 4 928
囚心锁ツ
囚心锁ツ 2020-12-04 21:12

I have strings like this:

var a = \"ABCFE\";

Is there a simple way that I can sort this string into:

ABCEF
<
4条回答
  •  温柔的废话
    2020-12-04 21:52

    You can use LINQ:

    String.Concat(str.OrderBy(c => c))
    

    If you want to remove duplicates, add .Distinct().

提交回复
热议问题