Advertisement
Janilabo

pe

Nov 29th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.07 KB | None | 0 0
  1. function StrPosExpression(ignore: Char; s, str: string; var position: Integer; var expression: string): Boolean;
  2. var
  3.   t: TStringArray;
  4.   h, i, l, p, f: Integer;
  5.   d: string;
  6. begin
  7.   expression := '';
  8.   position := 0;
  9.   Result := False;
  10.   l := Length(s);
  11.   if ((l > 0) and not (l > Length(str))) then
  12.   begin
  13.     d := StringOfChar(ignore, 1);
  14.     t := Explode(d, s);
  15.     h := High(t);
  16.     f := Pos(t[0], str);
  17.     l := (f + Length(t[0]));
  18.     if ((h > 0) and (f > 0)) then
  19.     begin
  20.       for i := 1 to h do
  21.       begin
  22.         p := PosEx(t[i], str, l);
  23.         if (p > 0) then
  24.           l := (p + Length(t[i]))
  25.         else
  26.           Exit;
  27.       end;
  28.       position := f;
  29.       expression := Copy(str, f, (l - f));
  30.       Result := True;
  31.     end;
  32.   end;
  33. end;
  34.  
  35. var
  36.   p: Integer;
  37.   str, exp: string;
  38.  
  39. begin
  40.   str := 'WHAAAAAAAT THE HECK IS THIS... This is just a damn test to prove the command works! OK?!';
  41.   ClearDebug;
  42.   if StrPosExpression('*', 'This * damn test * works!', str, p, exp) then
  43.     WriteLn('"' + exp + '" @' + IntToStr(p));
  44. end.
  45. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement