Copy some text from a string

I got this text inside a string

Description:</STRONG>something another something
more something<p> and yes more<BR><BR><BR>

What I want to do is copy the text between :</STRONG> and <BR> so I would get
something another something more something and yes more

So I think I need the position of
Description:</STRONG>
Then +1 the position until I get to <BR> then select that text and copy it.

the text between those two points will be different all the time....

Thanks guys!
LVL 10
wildzeroAsked:
Who is Participating?
 
mokuleCommented:
Since copy maybe a lengthy operation, You can do the same copying only once.

uses Strutils;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := Extract('Description:</STRONG>something another something more something<p> and yes more<BR><BR><BR>');
end;

function TForm1.Extract(Src: string): string;
var
  p1,p2: integer;
begin
  result := '';
  p1 := Pos('</STRONG>',Src);
  if p1 > 0 then
    begin
    p2 := PosEx('<BR>',Src,p1+1);
    Result := Copy(Src,p1+9,p2-p1-9);
    end;
end;
0
 
BlackTigerXCommented:
var
  originalText, extractedText:string;
  posi1:Integer;
begin
  originalText:='Description:</STRONG>something another something more something<p> and yes more<BR><BR><BR>';
  posi1:=Pos('/STRONG>', originalText)+8;
  extractedText:=Copy(originalText, posi1, Length(originalText)-posi1+1);
  extractedText:=Copy(extractedText, 1, Pos('<BR>', extractedText)-1);
  ShowMessage(extractedText)
end;
0
 
David_WardCommented:
// try this ...

function YourExtract(FromThis: String): String;
var
  s1: string;
begin
  delete(FromThis,1,pos('</STRONG>',FromThis)+9);

  s1:=copy(FromThis,1,pred(pos('<BR>',FromThis)));
  while pos('<p>',s1)<>0 do delete(s1,pos('<p>',s1),3);

  result:=s1;
end;

0
 
wildzeroAuthor Commented:
Thanks :D
Used a combination of the two!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.