Delphi - CompareStr 和 CompareString 之间的差异
我希望有人能为我阐明这一点: 在 Delphi 2009 中,CompareStr
(在 SysUtils 中定义)和 CompareString
(来自 Windows API)函数之间有什么区别?
两者都允许您指定要使用的区域设置,由于可用的比较标志,Windows 是否更“完整”?因此其中一个比另一个更快吗?
I'm hoping someone can shed some light on this for me:
What are the differences, in Delphi 2009, between the CompareStr
(defined in SysUtils) and CompareString
(from Windows API) functions?
Both let you specify the locale to be used, is the Windows one simply more "complete", due to the available comparison flags? Is one consequently faster than the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CompareString 使用区域设置信息,以便将 ae 和 æ 之类的内容视为匹配项,并且排序适合于地理区域。
CompareStr('', loInvariantLocale) 只是对字符串中的字符进行逐字节比较。 CompareStr('', loUserLocale) 在内部调用 CompareString,因此除了 CompareString 可以接受的附加标志之外,它们是相同的。它也是内联的,因此您不应该看到它与直接调用 CompareString 之间的速度有任何差异。
CompareString uses locale information so that things like ae and æ are treated as matches, and sorting is appropriate for the geographical region.
CompareStr('', loInvariantLocale) is just a byte-by-byte comparison of the characters in a string. CompareStr('', loUserLocale) calls CompareString internally, so they're identical, other than the additional flags that CompareString can accept. It's also inlined, so you shouldn't see any difference in speed between it and calling CompareString directly.