delphi – 最好的方法来找到一个字符串是否在一个列表(没有泛型)
我想做这样的事情:
Result = 'MyString' in [string1,string2,string3,string4]; 这不能用于字符串,我不想这样做: Result = (('MyString' = string1) or ('MyString' = string2)); 另外我认为,创建一个StringList来做这只是太复杂。 有没有其他方法来实现这一点? 谢谢。 解决方法
你可以使用AnsiIndexText(const AnsiString AText,const数组的字符串AValues):integer或MatchStr(const AText:string; const AValues:string of string):Boolean;
就像是 Result := (AnsiIndexText('Hi',['Hello','Hi','Foo','Bar']) > -1); 要么 Result := MatchStr('Hi',['foo','Bar']);
注意AnsiIndexText不区分大小写,MatchStr是区分大小写,所以我想它取决于你的使用 编辑:2011-09-3:刚刚发现这个答案,并想到我会添加一个注释,在Delphi 2010中还有一个MatchText函数,它与MatchStr相同,但case insenstive。 – 拉里 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |