strnicmp 相当于 UTF-8?

发布于 2024-09-03 10:16:22 字数 83 浏览 2 评论 0原文

我该如何对两个 UTF-8 编码的子字符串执行不区分大小写的比较?本质上,我正在寻找 UTF-8 的 strnicmp 函数。

What do I use to perform a case-insensitive comparison on two UTF-8 encoded sub-strings? Essentially, I'm looking for a strnicmp function for UTF-8.

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

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

发布评论

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

评论(2

梦在深巷 2024-09-10 10:16:22

各种Unicode脚本中的大小写转换规则非常困难,它需要大量的大小写转换表。你自己无法做到这一点,你需要一个图书馆。 ICU就是其中之一。

Case conversion rules in various Unicode scripts are murderously difficult, it requires large case conversion tables. You cannot get this right yourself, you'll need a library. ICU is one of them.

丶视觉 2024-09-10 10:16:22

strcoll 应该了解区域设置并正确对待 UTF8,至少如果它是区域设置的默认编码的话。如果不是,我仍然不知道。就像解决方法一样,您可以将多字节字符串转换为 wchars (mbrtowc),然后使用 wccasecmp,不幸的是它是 GNU 扩展,而不是标准库的一部分......也许不太有用。

strcoll should be locale aware and treat correctly UTF8 at least if it is the default encoding of the locale. If it is not, I have still no idea. Like a workaround, you can convert the multibyte string into wchars (mbrtowc) and then use wcscasecmp which unfortunately is a GNU extension, not a part of standard libraries... Not so useful maybe.

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