Delphi 泛型搜索字符串数组


本文整理自网络,侵删。

 
代码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 word转pdf两种方法

Delphi学习之资源文件dll的制作及使用

Delphi动态复选框源码

Delphi cef4 忽略不安全网站

Delphi中关键字inherited

Delphi 安卓 app 动态权限申请

Delphi 10.3 控件遮挡 webbrowser

Delphi 清除windows 图标缓存源代码

Delphi webbrowser载入自定义html内容并显示

Delphi双进程监控

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...