function TForm1 make_hash string integer var sum integer begin for to

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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;