首页 > 解决方案 > How to Sort a String in c#

问题描述

how can I sort characters within a string alphabetically?

I know this:

sorted = String.Concat(sorted.OrderBy(c => c));

but that would sort "bABa" like this:

"ABab"

what I want is "AaBb"

标签: c#

解决方案


尝试忽略大小写

sorted = String.Concat(sorted
  .OrderBy(c => char.ToUpper(c)) // sort ignoring case
  .ThenBy(c => c));              // on tie, i.e. 'A' and 'a' upper first  

推荐阅读