Advertisement
Janilabo

expr

Nov 30th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.79 KB | None | 0 0
  1. function StrPosExpressionEx(ignore: Char; s, str: string; var position: Integer): string;
  2. var
  3.   t: TStringArray;
  4.   h, i, l, p, f: Integer;
  5.   d: string;
  6. begin
  7.   position := 0;
  8.   Result := '';
  9.   l := Length(s);
  10.   if ((l > 0) and not (l > Length(str))) then
  11.   begin
  12.     d := StringOfChar(ignore, 1);
  13.     t := Explode(d, s);
  14.     h := High(t);
  15.     f := Pos(t[0], str);
  16.     l := (f + Length(t[0]));
  17.     if ((h > 0) and (f > 0)) then
  18.     begin
  19.       for i := 1 to h do
  20.       begin
  21.         p := PosEx(t[i], str, l);
  22.         if (p > 0) then
  23.           l := (p + Length(t[i]))
  24.         else
  25.           Exit;
  26.       end;
  27.       position := f;
  28.       Result := Copy(str, f, (l - f));
  29.     end;
  30.   end;
  31. end;
  32.  
  33. function StrPosExpression(ignore: Char; s, str: string): string;
  34. var
  35.   t: TStringArray;
  36.   h, i, l, p, f: Integer;
  37.   d: string;
  38. begin
  39.   Result := '';
  40.   l := Length(s);
  41.   if ((l > 0) and not (l > Length(str))) then
  42.   begin
  43.     d := StringOfChar(ignore, 1);
  44.     t := Explode(d, s);
  45.     h := High(t);
  46.     f := Pos(t[0], str);
  47.     l := (f + Length(t[0]));
  48.     if ((h > 0) and (f > 0)) then
  49.     begin
  50.       for i := 1 to h do
  51.       begin
  52.         p := PosEx(t[i], str, l);
  53.         if (p > 0) then
  54.           l := (p + Length(t[i]))
  55.         else
  56.           Exit;
  57.       end;
  58.       Result := Copy(str, f, (l - f));
  59.     end;
  60.   end;
  61. end;
  62.  
  63. var
  64.   position: Integer;
  65.   str, expr: string;
  66.  
  67. begin
  68.   str := 'WHAAAAAAAT THE HECK IS THIS... This is just a damn test to prove the command works! OK?!';
  69.   ClearDebug;
  70.   expr := StrPosExpression('*', 'This * damn test * works!', str);
  71.   if (expr <> '') then
  72.     WriteLn('"' + expr + '"');
  73.   expr := StrPosExpressionEx('*', 'This * damn test * works!', str, position);
  74.   if (expr <> '') then
  75.     WriteLn('"' + expr + '" @' + IntToStr(position));
  76. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement