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 用api函数抓取屏幕图像

Delphi监视进程并结束进程

Delphi响应wmi事件(响应网线断开)

Delphi lockbox 做加密解密

Delphi 一个文件重复生成的小工具[附源码]

Delphi 之 编辑框控件(tedit)

Delphi字符串加密解密

Delphi里formatfloat的用法

Delphi 2009 之 tcategorypanelgroup[2]: headeralignment、gradientdirection

Delphi字符串深入学习

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



打赏

取消

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

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

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

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

评论

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