本文介绍了自定义归类排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有.NET / C#的方式来排序列表<串> 根据自定义的字母顺序

Is there a way in .NET/C# to sort a List<string> according to a custom alphabetical order?

我有一个单词列表:

{ "badum", "śiram", "ðaur", "hor", "áltar", "aun" }

这是我希望按以下顺序进行排序:

that I wish to sort in the following order:

{ "áltar", "aun", "badum", "śiram", "hor", "ðaur" }

通过自定义的字母顺序,我的意思是我工作的一个的:ABZTMIGJLNKSOŚPRFUHDVEÐÞY。 A C#实现的 RuleBasedCollat​​or 在爪哇发现将是完美的!如果没有这样的东西存在,在编写自定义算法的几个三分球,将不胜感激。

By custom alphabetical order, I mean that I'm working on a constructed language with an alphabet that looks like this: ABZTMIGJLNKSOŚPRFUHDVEÐÞY. A C# implementation of the RuleBasedCollator found in Java would be perfect! If no such thing exists, a few pointers on writing a custom algorithm would be appreciated.

感谢您提前。

推荐答案

我肯定会下手创建RuleBasedCollat​​or。弄清楚你想要的是的困难任务之一的规则。

I would definitely start with creating a RuleBasedCollator. Figuring out the rules that you want is one of the harder tasks.

有是提供的网绑定可能适合你。

There is a project that provides .net bindings over icu which may suit you.

如果不符合您的要求,并决定编写自己的是一个很好的资源。请记住,自然语言概念排序(尽管许多优化是可能的)涉及随着特异性单独的通道。第一遍会寻找所谓的主要区别(通常是忽略大小写和某些符号和标点符号的差异)如果没有差异和基本单位的两个字符串的数量是一样的,那么你可以让二传,这无暇顾及变音符号的差异,如果有的话。接下来你处理大小写区别,最后标点的区别。

If that doesn't meet your requirements, and you decide to write your own, the Unicode Collation Algorithm is a good resource. Keep in mind that natural language sorting conceptually (although many optimizations are possible) involves separate passes with increasing specificity. The first pass will look for so-called primary distinctions (usually ignoring differences of case and certain diacritics and punctuation) if there are no differences and the number of primary units in both strings is the same, then you can make the second pass, this time taking into account diacritic differences, if any. Next you process the case distinctions and finally punctuation distinctions.

这篇关于自定义归类排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:34