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 清除字符串两边空格或指定字符

Delphi xe datasnap服务器获取客户端ip地址

Delphi内存映射大文件

Delphi xe10 手机程序事件服务操作、退出键操作

Delphi中关键字inherited

Delphi idhttp读取网页重定向

Delphi 一句话获取文件的最新修改时间

Delphi webbrowser 使滚动条滚动到底部

Delphi图像二值化

Delphi7 写过卡巴主动防御服务端

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



打赏

取消

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

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

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

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

评论

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