简体   繁体   English

如何从 delphi 中某行之前删除文本

[英]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.

相关问题 如何从Python Requests / Beautiful Soup中的某些文本参数获取HTML的特定行 - How do I get specific line of HTML from certain text parameter in Python Requests/Beautiful Soup 如何从引导导航栏中删除该白线并更改文本颜色? - How do I remove this white line from my bootstrap navbar and change the text colors? 我如何 select 文本文件中的某些“节点” - 基于使用 HTMLAgilityPack 的某行包含的内容? - How do I select certain 'Nodes' in a text file - based off of what a certain line contains using HTMLAgilityPack? 如何在Python的已保存文件中的包含某些文本的行之后打印行? - How do I print a line following a line containing certain text in a saved file in Python? 如何从具有 SVG 背景的按钮中删除垂直线? - How do I remove a vertical line from a button with SVG background? 如何从我的博客中删除垂直线? - How do I remove vertical line from my blog? 如何使文本停在某个点并转到下一行? - How do I make text stop at a certain point and go onto the next line? 我如何删除<br>在帐单地址和显示地址和城市文本之前的值(woocommerce 谢谢页面)? - How do I remove the <br> in billing address and display address and city text before the value ( woocommerce thankyou page )? 如何从输入控件中删除选定的文本? - How do I remove selected text from an input control? HTML:如何从图像和文本中删除超链接下划线? - HTML: How do I remove hyperlink underline from an Image and text?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM