如何在.NET中使用非英文引号进行格式化?

发布于 2024-12-08 19:42:03 字数 253 浏览 0 评论 0 原文

最近在奥地利度假时,我注意到引号看起来与我在英国习惯看到的引号不同。查看维基百科表明,世界各地情况截然不同

鉴于我已经在 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

往事随风而去 2024-12-15 19:42:03

不幸的是,.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...

不交电费瞎发啥光 2024-12-15 19:42:03

这就是 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.

拥抱我好吗 2024-12-15 19:42:03

这似乎确实是 NLS 数据中的遗漏。然而,很难想象一个可以以编程方式单独构造引用文本的示例。实际上,您将依赖本地化来提供包含引号的任何文本,例如 'a "string"' 将被翻译为法语的 'une «chaîne»'。引号通常是本地化问题而不是文化格式问题。因此,如果您确实需要构造带引号的文本,则可以通过将引号添加到字符串表来解决问题,假设您的应用程序正在本地化(如果您不本地化,则引号保持不变可能是一件好事)用英语讲)。

例如,您的 en-US 字符串(为了清楚起见,省略了分隔字符串的引号):

“{0}”

fr-FR 版本为:

《{0}》

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:

"{0}"

And the fr-FR version would be:

«{0}»

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文