Well is there any built-in function to do this ?, or 3rd party library


EXAMPLE code

source := Sock.Get('http://www.google.com/');

if source('Google Search Engine', a) > 0 then 
begin
 NeededPattern := GetPattern(source, '<font>','</font>');
 result := neededPattern; // will display ABC of the <font>ABC</font>
end;

Then it will get the middle of the font HTML result

There is no builtin function for what you want. It is easy to create though.

Use Pos to find the "<font>" and get the position of the "<". Then add the length of "<font>" to get the position of the desired text.

Then use PosEx to find the position of the first "</font>" after the desired text and calculate the length of the text;

Then use Copy to extract the desired text;

function GetPattern(Source, before, after : String) : String;
  var
    p, l : Integer;
  begin
  p := Pos(Source, before);
  if p < 1 then
    begin
    result := '';
    end
  else
    begin
    p := p + Length(before);
    l := PosEx(Source, after, p);
    if l < 1 then
      begin
      result := '';
      end
    else 
      begin
      l := l - p;
      result := copy(Source, p, l);
      end;
    end;
  end;

Delphi includes RegularExpressions with which you can do this, but am not sure from which version. For earlier version TPerlRegex is available (3rd party).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.