本文整理自网络,侵删。
代码1:uses StrUtils;procedure TForm1.FormCreate(Sender: TObject);var someArray: TArray; begin someArray:=TArray.Create('One','Two','Three'); if MatchStr('Two', someArray) then ShowMessage('It contains Two');end;
代码2:{$APPTYPE CONSOLE}
{$R *.res}
uses Generics.Defaults, Generics.Collections, System.SysUtils;
Var someArray: TArray; FoundIndex : Integer;
begin try someArray:=TArray.Create('a','b','c'); if TArray.BinarySearch(someArray, 'b', FoundIndex, TStringComparer.Ordinal) then Writeln(Format('Found in index %d',[FoundIndex])) else Writeln('Not Found'); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln;end.注意:BinarySearch要求对数组进行排序。
相关阅读 >>
Delphi webbrowser载入自定义html内容并显示
更多相关阅读请进入《Delphi》频道 >>