c# - 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"
解决方案
尝试忽略大小写:
sorted = String.Concat(sorted
.OrderBy(c => char.ToUpper(c)) // sort ignoring case
.ThenBy(c => c)); // on tie, i.e. 'A' and 'a' upper first
推荐阅读
- angular - 如何从 index.html 在 Angular 8 应用程序中动态定义“base href”?
- python - 如何在 wagtail 页面中发送额外的上下文
- linux - 使用 grep 移动具有特定扩展名的文件
- git - Git push to origin/feature 错误可能是由于 rebase-reassigned 提交 SHA
- python - 服务器迁移后奇怪的python脚本错误
- solr - PorterStemFilterFactory 不返回结果
- java - 该代码正在删除整个文件,而不是在 Java 中修改我想要的行
- c# - 简单地将 Entity Framework Core 添加到基本的 Azure 函数应用程序会导致错误
- java - 如何在没有业务逻辑中断的情况下处理 Java InterruptedException?
- python - 如何获取文本文件中两行之间的数据?