function TForm1.make_hash(s: string): integer;
var i,sum: integer;
begin
for i:=0 to length(s) do
begin sum:=sum + ord(s[i]);
end;
Result:=sum mod 10;
end;
procedure TForm1.BitBtn6Click(Sender: TObject);
var filename: string;
var hash: integer;
begin
filename:= FileListBox1.FileName;
hash:= make_hash(filename);
ShowMessage(filename+' '+inttostr(hash)) ;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
var f: Textfile;
var ch: char;
var word, filename: string;
var c,c1,c2, inword, maxlen: integer;
var list1, list2: tstringlist;
begin
list1 := tstringlist.create();
list2 := tstringlist.create();
filename:= FileListBox1.FileName;
assignfile (f, filename );
reset(f);
inword := 0;
while (not Eof(f))
do begin
read(f,ch);
if ch in ['A'..'Z', 'a'..'z'] then
begin
if inword = 0 then
begin
inword := 1;
word := ch;
end
else
word := word + ch;
end;
if ch in ['A'..'Z', 'a'..'z'] then else
begin
if inword = 1 then
begin
list1.append(word);
word := '';
inword := 0;
end;
end;
end;
maxlen:=0;
for c:=0 to list1.Count-1 do begin
if length(list1[c]) > maxlen then maxlen := length(list1[c])
end;
for c:=0 to list1.Count-1 do
begin
if length(list1[c]) = maxlen then ShowMessage(list1[c]);
end;
{
c1:=0;
while c1<10 do begin
for c:=0 to list1.Count-1 do begin
if length(list1[c])=maxlen then begin
list2.append(list1[c]); list1.Delete(c);
inc(c1);
end;
for c:=0 to list1.Count-1 do begin
if length(list1[c]) > maxlen then maxlen := length(list1[c]);
end;
end;
end;
}
end;
function TForm1.CountLink(const S: String): integer;
begin
with TRegExpr.Create do
try
Expression := '^(?im).*?<a href="(.*?)html"(.*?)</a>.*$';
if Exec(S)
then Result := length(Match[1])
else Result := 0;
finally
Free;
end;
end;
procedure TForm1.BitBtn8Click(Sender: TObject);
{function GetLink(const S: String;n: integer): String;
var r: TRegExpr;
begin
with TRegExpr.Create do
try
Expression := '^(?im).*?<a href="(.*?)html"(.*?)</a>.*$';
if Exec(S)
then Result := Match[n]
else Result := 'No links found';
finally
Free;
end;
end; }
function GetLinks(const S: String): String;
var r: TRegExpr;
begin
Result := '';
r := TRegExpr.Create;
try
r.Expression := {'[\w_-]*?.html'}'[a-zA-Z\-\d\W]*.[^/\\<\>]html';
if r.Exec(S) then
REPEAT
Result := Result + r.Match [0] + ',';
UNTIL not r.ExecNext
else Result := 'No links found';
finally
r.Free;
end;
end;
var
Html: TStringList;
filename: string;
n: integer;
begin
Html := TStringList.Create;
filename:= FileListBox1.FileName;
try
Html.LoadFromFile(filename);
{for n:=1 to CountLink(Html.Text) do
begin }
ShowMessage(GetLinks(Html.Text));
{end; }
finally
Html.Free;
end;
end;