Search for a word from a list in Memo
How to implement a search in the Memo string from the word list
I wrote a search function for a word from the list
function scan(s:string):integer;
begin
result:= pos('слово1',s) or pos('слово2',s) or pos('слово 3',s);
end;
Implementation.
if scan(memo1.Lines[0]) <> 1 then
begin
{Записать найденное слово, например, в массив}
mas[i]:=
end;
P.S. it is known that only one of the search words will occur in each line
The result should be: search words: delphi, text, programming
S:='output the word delphi';
Mas[i] will be equal to delphi
0
1 answers
The scan
function should return the found word, not its position in the string:
function scan(s: string): string;
var
Position: Integer;
const
WORD_1 = 'слово1';
WORD_2 = 'слово2';
WORD_3 = 'слово 3';
begin
Position := pos(WORD_1, s);
if Position > 0 then
Result := copy(s, Position, Length(WORD_1))
else
begin
Position := pos(WORD_2, s);
if Position > 0 then
Result := copy(s, Position, Length(WORD_2))
else
begin
Position := pos(WORD_3, s);
if Position > 0 then
Result := copy(s, Position, Length(WORD_3))
else
Result := ''; // не нашли
end;
end;
end;
And then do a loop on all the lines in memo1
and mas[i] := scan(memo1.Lines[i])
.
1
Author: kot-da-vinci, 2016-02-26 06:50:38