如何在 C# 中枚举本地化字母表?
首先,这不是以下内容的重复: 枚举字母表的最快方法
因为我需要获取所有任意(可变)语言的字母表中的字符,并且按正确的顺序排列。
如果不知道每种可能的文化/语言的字母表,我该如何做到这一点? 例如,System.Gobalization.Cultureinfo 包含有关日期格式、排序方法和代码页信息的信息。但不是关于字母表本身的信息。 此外,'A' 到 'Z' 的排序迭代是行不通的,因为例如德语有 äÖÜ 之类的字符,这些字符在代码页编号中位于 'Z' 之后,但在排序时位于 aou 后面。
我可以以某种方式使用代码页来获取所有字符,并以某种方式对它们进行排序吗? 我所说的“所有字符”是指所有字母,包括数字,但不包括标点符号。 并且可能只有大写异或小写。
First of all, this is not a duplicate of:
Quickest way to enumerate the alphabet
Because I need to get all the characters of the alphabet OF AN ARBITRARY (variable) LANGUAGE, and that in the correct ordering sequence.
How can I do that without knowing the alphabet of every possible culture/language ?
System.Gobalization.Cultureinfo for example has information on date format, and a sorting method, and codepage info. But not info on the alphabet itselfs.
Forthermore 'A' to 'Z' ordering iterating won't do, because German for example has characters such as ÄÖÜ, which are after 'Z' in the codepage numbering, but follow after aou when sorting.
Can I somehow use the codepages to get all the characters, and sort them somehow ?
By 'all the characters' I mean all letters, including numbers, but not punctuation marks.
And possibly only upper XOR lowercase.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,我要说的是,我同意其他人的说法。您认为字符
é
是有效的美国英语字符吗?它经常被使用,但它不在普通的“az”中。也就是说,这里有一些代码(VB2010)。此代码调用非托管函数
GetLocaleInfoW
并请求包含 Unicode 代码点范围的LOCALESIGNATURE
结构。此信息用于确定给定字体所需的范围。Char
结构不支持所有 Unicode 代码点,因此该函数返回String
。在该链接底部查找“代理对”以获取更多信息。不幸的是,这段代码并不能完成您想要的一切。例如,经常引用的芬兰语没有字母
W
,但在 Windows 中,该字符存在于有效代码点范围内。我不知道有什么办法可以深入了解这一点。First off, let me say that I agree with what everyone else is saying. Would you consider the character
é
to be a valid US English character? It gets used pretty often but its not in the normal "a-z".That said, here's some code (VB2010). This code calls into the unmanaged function
GetLocaleInfoW
and asks for aLOCALESIGNATURE
structure which contains Unicode code point ranges. This information is used to determine what ranges are needed for a given font.The
Char
structure doesn't support all of the Unicode code points so the function returnsString
s instead. Look for "Surrogate pair" at the bottom of that link for more info.This code doesn't do everything that you want, unfortunately. For example, the oft cited Finnish language doesn't have the letter
W
but in Windows the character exists in the valid code-point range. I don't know a way of getting down to the nitty-gritty on that.我不认为.Net框架提供了你想要的东西。首先,并非所有语言都有西方意义上的字母。其次,即使您将覆盖范围限制为那些具有字母表的语言,迭代代码页的内容也不起作用,因为许多代码页覆盖多种语言(例如,CP 1252 覆盖主要的西欧语言)。第三,Windows 上最近支持的一些语言没有代码页。我认为除了先验了解您感兴趣的语言的字母表之外,没有其他解决方案。
也许如果您解释了您想要实现的目标,可能会建议更好的解决方案。
I don't think that the .Net framework provides what you want. First of all, not all languages have alphabets in the western sense of the word. Second, even if you limit your coverage to those languages that have alphabets, iterating through the contents of a code page won't work because many code pages cover several languages (eg, CP 1252 covers the main western european languages). Third, some of the more recently supported languages on Windows don't have code pages. I don't think there is a solution outside of having a priori knowledge of the alphabets of the languages you're interested in.
Perhaps if you explained what you are trying to achieve, a better solution could be suggested.
如果您想要枚举字母表的原因是为了生成索引,那么您可以使用 Windows.Globalization.Collation.CharacterGroupings
If your reason for wanting to enumerate an alphabet is to produce an index, then you can use Windows.Globalization.Collation.CharacterGroupings