0

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

3
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by pritaeas
0

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;
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.