[英]How do I remove text from before a certain line in delphi
<h1 class="tt">example</h1></div><div class="bl_la_main"><div class="divtext">
I am trying to remove everything before <div class="bl_la_main">
but keep everything after it.我正在尝试删除<div class="bl_la_main">
之前的所有内容,但保留其之后的所有内容。
Any help would be appreciated.任何帮助,将不胜感激。 Thanks谢谢
PS: Since I misunderstood the question, I first created the "take the before terms" function. PS:由于我误解了问题,我首先创建了“采取之前的条款”function。
You can take it like this.你可以这样对待。
procedure TForm1.Button1Click(Sender: TObject);
var
HTML: string;
begin
HTML := '<h1 class="tt">example</h1></div><div class="bl_la_main"><div class="divtext">';
Delete(HTML, Pos('<div class="bl_la_main">', HTML) - 1, Length(HTML) - Pos('<div class="bl_la_main">', HTML));
ShowMessage(HTML);
end;
If we need to make it functional;如果我们需要让它发挥作用;
function parseHTML(html: string; substr: string): string;
begin
Delete(HTML, Pos(substr, HTML) - 1, Length(HTML) - Pos(substr, HTML));
Result := HTML;
end;
Use:利用:
function parseHTML(html: string; substr: string): string;
begin
Delete(HTML, Pos(substr, HTML) - 1, Length(HTML) - Pos(substr, HTML));
Result := HTML;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
HTML: string;
begin
HTML := '<h1 class="tt">example</h1></div><div class="bl_la_main"><div class="divtext">';
ShowMessage(parseHTML(HTML, '<div class="bl_la_main">'));
end;
Result:结果:
<h1 class="tt">example</h1></div">
I created it separately, in a functional way to take both before and after.我以一种功能性的方式单独创建了它,前后都可以使用。
function parseHTMLAfter(html: string; substr: string): string;
begin
Delete(HTML, Pos(substr, HTML) - 1, Length(HTML) - Pos(substr, HTML));
Result := HTML;
end;
function parseHTMLBefore(html: string; substr: string): string;
begin
Delete(HTML, 1, Pos(substr ,html) - 1);
Result := HTML;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
HTML: string;
begin
HTML := '<h1 class="tt">example</h1></div><div class="bl_la_main"><div class="divtext">';
ShowMessage(parseHTMLBefore(HTML, '<div class="bl_la_main">'));
end;
Result:结果:
<div class="bl_la_main"><div class="divtext">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.