频道分类

delphi 判断文本是否包含多个关键词之一

作者:admin 来源: 日期:2020/3/27 13:04:35 人气: 标签:

 
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Memo2: TMemo;
    Button1: TButton;
    Memo3: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function Check_keyword(const txt: string;keywordlist:tstringlist): Boolean;
var
  I: Integer;
begin
 Result :=false;
  keywordlist.beginUpdate;
for I := 0 to keywordlist.Count-1 do
begin
if pos(keywordlist.Strings[I],txt)>0 then
begin
Result :=true;
Break;
end;
end;
keywordlist.endUpdate;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
key:tstringlist;
begin
key:=tstringlist.Create;
key.Text:=Memo1.Text;

Memo3.Clear;

if Check_keyword(Memo2.Text,key) then
begin
Memo3.Lines.Add('存在');
end
else
begin
Memo3.Lines.Add('不存在');
end;

end;

end.

上一篇:delphi TThread线程同步下一篇:没有资料