最近在奥地利度假时,我注意到引号看起来与我在英国习惯看到的引号不同。查看维基百科表明,世界各地情况截然不同。
鉴于我已经在 C# 代码中使用了区域性相关的小数点和列表分隔符,我还想使用正确的引号。有谁知道我在哪里(如果有的话)可以在 .NET 框架类中找到相关字符?
While on holiday in Austria recently, I noticed that quotation marks looked different to the ones I'm used to seeing here in Britain. Checking Wikipedia shows that things are quite different all around the world.
Given that I already use culture-dependent decimal and list separators in my C# code, I'd like to also use the correct quotation marks. Does anyone know where, if anywhere, I'd find the relevant characters in the .NET framework classes?
发布评论
评论(3)
不幸的是,.Net 本身不会向您提供此类信息。您需要另一个来源。
我想到的是 ICU,即 ICU4C 实际上是从
无论如何,您需要实际从 ulocdata_getDelimiter href="http://icu-project.org/apiref/icu4c/ulocdata_8h.html" rel="nofollow">ulocdata.h 传递适当的 ULocaleDataDelimiterType 常量,即您感兴趣的实际引号。
当然,首先您需要实际导入(至少)DLL 之一并实例化ULocaleData 但这是可能的。
我知道它远没有使用 TextInfo 那么容易(据我们所知,它不提供此类信息)但是......
Unfortunately, .Net won't give you such information on its own. You need another source.
The one I have in mind is ICU, namely ICU4C which in fact reads these from CLDR.
Anyway, you would need to actually call ulocdata_getDelimiter from ulocdata.h passing appropriate ULocaleDataDelimiterType constant, that is the actual quotation mark you are interested in.
Of course first you would need to actually import (at least) one of the DLL's and instantiate ULocaleData but it is possible.
I know it is nowhere near as easy as using TextInfo (which as we know does not provide such information) but...
这就是 Unicode 字符,.NET 和大多数字符字体都支持这些字符。
维基百科上有一个极其详细的讨论:http://en.wikipedia.org/wiki/Quotation_mark_glyphs。
在 C# 中,您可以根据该文章中的表格使用“\u00AB”来定义左 guillemet:« - 等等。
That'll be the Unicode characters, which are supported out-of-the-box in .NET and most character fonts.
An obscenely detailed discussion is on Wikipedia here: http://en.wikipedia.org/wiki/Quotation_mark_glyphs.
In C#, you'd use e.g. "\u00AB" to define the left-guillemet: « - and so on, based on the table in that article.
这似乎确实是 NLS 数据中的遗漏。然而,很难想象一个可以以编程方式单独构造引用文本的示例。实际上,您将依赖本地化来提供包含引号的任何文本,例如
'a "string"'
将被翻译为法语的'une «chaîne»'
。引号通常是本地化问题而不是文化格式问题。因此,如果您确实需要构造带引号的文本,则可以通过将引号添加到字符串表来解决问题,假设您的应用程序正在本地化(如果您不本地化,则引号保持不变可能是一件好事)用英语讲)。例如,您的 en-US 字符串(为了清楚起见,省略了分隔字符串的引号):
fr-FR 版本为:
It does seem like an omission in the NLS data. However it's hard to think of an example where you would programmatically construct quoted text in isolation. In practice you would rely on localization to provide whatever text includes quotation marks and for example
'a "string"'
would get translated to'une «chaîne»'
in French. The quotes are typically a localization issue rather than a culture formatting issue. As such, should you really need to construct quoted text, you could solve the problem by adding the quotes to your string table, assuming your app is getting localized (if you don't localize, it's probably a good thing that the quotes stay as in English).For example your en-US string (with the quotes delimiting the string omitted for clarity) would be:
And the fr-FR version would be: