简体   繁体   English

如何创建不区分大小写的字符串列表?

[英]How do I create a case insensitive list of string?

I'm trying to create a list of string that is case-insensitive. 我正在尝试创建不区分大小写的字符串列表。

The CreateList method let's me pass in some overloads: CreateList方法让我传递一些重载:

  • TComparison<System.string>
  • IComparer<System.string>

I tried to use TStringComparer.OrdinalIgnoreCase like this: 我试图像这样使用TStringComparer.OrdinalIgnoreCase

var
  List: IList<string>;
begin
  List := TCollections.CreateList<string>(TStringComparer.OrdinalIgnoreCase);
end;

But since this comparer doesn't implement any of the above classes / interfaces that doesn't compile; 但是,由于此比较器未实现上面未编译的任何类/接口,因此, I get: 我得到:

E2250 There is no overloaded version of TCollections.CreateList<System.string> that can be called with these arguments E2250没有可以使用这些参数调用的TCollections.CreateList<System.string>重载版本

Is there an implementation of one of those available in the spring4d framework? 在spring4d框架中是否可以实现其中之一?

You need to write the parentheses: 您需要写括号:

var
  List: IList<string>;
begin
  List := TCollections.CreateList<string>(TStringComparer.OrdinalIgnoreCase());
end;

Later compiler versions can figure it out without. 更高版本的编译器可以解决这个问题。

After closer inspection of the type TComparison : 在仔细检查TComparison类型TComparison

type
  TComparison<T> = reference to function(const Left, Right: T): Integer;

The answer turns out to be quite tivial: 答案非常有野心:

var
  List: IList<string>;
begin
  List := TCollections.CreateList<string>(AnsiCompareText);
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何调整SuperObject库以使其不区分大小写? - How can I tweak SuperObject library to make it behave case-insensitive? 不区分大小写的位置 - case insensitive Pos 如果未命名案例变量,如何判断变量记录中哪个案例有效,以及如何创建此类记录的值? - How do I tell which case is valid in a variant record when the case variable isn't named, and how do I create values of such records? 在delphi中如何使用null分隔符创建字符串 - In delphi how do I create a string with null separator 如何在OSX Yosemite上以不区分大小写的方式比较文本 - How to compare text in a case insensitive way on OSX Yosemite 如何使用TIdHTTP中的字符串创建IHTMLDocument2? - How do I create an IHTMLDocument2 using a string from TIdHTTP? 如何从提供类名的字符串创建实例? - How do I create an instance from a string that provides the class name? 如何使用 TStringHelper 测试两个字符串是否不区分大小写? - How to test two strings for odinal case-insensitive equality using TStringHelper? 如何从逗号分隔的字符串对列表中填充TDictionay? - How do i fill a TDictionay from a list of comma-separated string pairs? 如何激活case语句的代码完成? - How do I activate code completion for case statements?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM