delphi 如何循环获取网页源码中两个字符串之间的内容

mzwcs 2015-09-17 03:36:00
delphi 如何循环获取网页源码中两个字符串之间的内容,并写入数组
function GetStr(Str,StrBegin,StrEnd,strxunhuan:string;Isxunhuan :Boolean = false):string;
str 全部文本
StrBegin :开始文本
StrEnd :结束文本
返回 :开始文本和结束文本之间的文本内容
isxunhuan(数组) : false(默认)的话不循环获取,true的话循环获取 (可不输入)

自己写了个不能循环的,循环的怎么写呢?
begin
in_star:=AnsiPos(strbegin,Str)+length(strbegin);
in_end:=AnsiPos(strend,Str);
result:=copy(Str,in_star,in_end-in_star);
end

求大神帮忙写个函数,感激不尽
...全文
793 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
让缘随风 2017-05-19
  • 打赏
  • 举报
回复
我也有类似问题,请问解决了吗,麻烦把正确的函数及用法贴出来一下,谢谢!
bdmh 2015-09-18
  • 打赏
  • 举报
回复
你用正则好了,指定首尾字符串,直接就给你返回所有的结果了
wdonghai 2015-09-17
  • 打赏
  • 举报
回复
...... type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Memo1: TMemo; Memo2: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure StrSplite(AStr,ASBegin,ASEnd:string;AStrings:TStrings;AIsXunHun:Boolean=True); var iB,iE:Integer; s:string; begin iB:=Pos(ASBegin,AStr); if iB>0 then begin iE:=Pos(ASEnd,AStr); if iE>0 then begin iB:=iB+length(ASBegin); s:=Copy(AStr,iB,iE-iB); AStrings.Add(s); if AIsXunHun then begin AStr:=Copy(AStr,iE+length(ASEnd),length(AStr)); StrSplite(AStr,ASBegin,ASEnd,AStrings,AIsXunHun); end; end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Memo2.Clear; StrSplite(Memo1.Text,edit1.Text,edit2.Text,Memo2.Lines,True); end;
pathletboy 2015-09-17
  • 打赏
  • 举报
回复
这类任务建议使用正则表达式来完成。

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧