比较和排序Unicode文件名 [英] Comparing and sorting Unicode filenames

查看:204
本文介绍了比较和排序Unicode文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Delphi 2007和TMS组件用于Unicode utils和界面(不能将其升级到Delphi 2009以支持Unicode).

Using Delphi 2007 and TMS components for Unicode utils and interface (upgrading to Delphi 2009 for Unicode support is not an option).

我将文件名列表存储在字符串列表(TTntStringList)中.它已排序且不区分大小写.默认的排序例程使用CompareStringW(LOCALE_USER_DEFAULT,NORM_IGNORECASE,...)比较字符串(与查找"相同).但是,这是一个问题,因为这会将dummyss.txt与dummyß.txt等同起来,但是在NTFS上,将这两个文件放在同一文件夹中是完全合法的,也就是说,将它们视为不同的名称.

I'm storing a list of filenames in a string list (TTntStringList). It's sorted and case insensitive. The default sort routine uses CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, ...) to compare strings (and the same for Find). However, this is a problem because that will equate dummyss.txt with dummyß.txt (for example), but on NTFS it's perfectly legal to have those two files in the same folder, i.e. they are treated as different names.

我的理解是,在Vista和更高版本上,比较文件名的正确方法是使用CompareStringOrdinal.这是正确的吗?

My understanding is that on Vista and newer, the correct way to compare filenames is to use CompareStringOrdinal. Is this correct?

在Vista之前的系统上,正确的方法是什么?我相信应该是CompareStringW(LOCALE_INVARIANT,...),但我不确定.

On pre-Vista systems, what would be the correct way? I believe it should be CompareStringW(LOCALE_INVARIANT, ...) but I'm not entirely sure.

谢谢

推荐答案

MSDN文章

CompareStringOrdinal 比较两个 Unicode字符串以测试二进制 平等,而不是语言 平等.这样的例子 非语言字符串是NTFS文件 名字...

CompareStringOrdinal compares two Unicode strings to test for binary equality, as opposed to linguistic equality. Examples of such non-linguistic strings are NTFS file names, ...

CompareStringOrdinal需要Windows Vista或更高版本.

CompareStringOrdinal requires Windows Vista or later.

是的,它似乎在Vista之前的Windows中,您也可以使用 RtlCompareUnicodeString ,它也由CompareStringOrdinal内部使用,并且从Windows NT开始可用.

Yes, it seems that in pre-Vista Windows you can use RtlCompareUnicodeString which is used internally by CompareStringOrdinal, too, and is available since Windows NT.

这篇关于比较和排序Unicode文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆