unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, BMH, strutils;
type
{ TForm1 }
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
function NextPosBMH(SearchStr, Str:
string; Position: Integer): Integer;
begin
Delete(Str, 1, Position - 1);
Result := Search_BMH_Unrolled(Str,SearchStr);
if Result = 0
then Exit;
if (Length(Str) > 0)
and (Length(SearchStr) > 0)
then
Result := Result + Position + 1;
end;
Function CountWordsStd(
Const text, wort :
String) : Integer;
Var
i : Integer;
Begin
i:=1;
Result := 0;
repeat
i := PosEx(wort,text,i)+1;
if i > 1
then inc(Result)
else exit;
until false
End;
Function CountWordsStdBMH(
Const text, wort :
String) : Integer;
Var
i : Integer;
Begin
i:=1;
Result := 0;
repeat
i := NextPosBMH(wort,text,i)+1;
if i > 1
then inc(Result)
else exit;
until false
End;
procedure TForm1.Button1Click(Sender: TObject);
//Std Pos
var
Filestream : TFileStream;
SuchWort, SuchText:
String;
begin
SuchWort:= Edit1.Text;
Filestream:=TFileStream.Create('
test.txt',fmOpenRead);
Try
SetLength(SuchText,Filestream.Size);
Filestream.
Read(SuchText[1],Length(SuchText));
Label1.Caption:= IntToStr(CountWordsStd(SuchText,SuchWort));
Finally
Filestream.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
// BMH
var
Filestream : TFileStream;
SuchWort, SuchText:
String;
begin
SuchWort:= Edit1.Text;
Filestream:=TFileStream.Create('
test.txt',fmOpenRead);
Try
SetLength(SuchText,Filestream.Size);
Filestream.
Read(SuchText[1],Length(SuchText));
Label1.Caption:= IntToStr(CountWordsStdBMH(SuchText,SuchWort));
Finally
Filestream.Free;
end;
end;
end.