procedure GetStrFromMemo(SourceMemo: TMemo; Keywords: String; var ResList: TStringList); //帮你写了个函数,可直接调用 SourceMemo为源memo, Keywords为特定字符, ResList为包含关键字的所有段落集合
var
i: Integer;
SourceList: TStringList;
begin
if ResList = nil then Exit;
SourceList := TStringList.Create;
SourceList.DelimitedText := #13#10;
SourceList.DelimitedText := SourceMemo.Lines.Text;
for i:= 0 to SourceList.Count - 1 do
begin
if Pos(Keywords, SourceList.Strings[i]) > 0 then
ResList.Add(SourceList.Strings[i]);
end;
SourceList.Free;
end;
//以按钮事件为例,特定字符假设写在了edit1里面,调用方法具体如下
procedure TForm1.Button1Click(Sender: TObject);
var
MyStrList: TStringList;
begin
MyStrList := TStringList.Create;
GetStrFromMemo(Form1.Memo1, Form1.Edit1.Text, MyStrList);
Showmessage('包含特定字符的段落一共有 ' + IntToStr(MyStrList.Count) + ' 段');
if MyStrList.Count > 0 then
Showmessage('第一段内容为:' + #13#10 + MyStrList.Strings[0]); //这里就取了第一段,如果符合要求的有好几段且都要的话,那你可以用循环全部取出来
MyStrList.Free;
end;