Janilabo

Janilabo | LastBefore() [SCAR Divi]

Apr 28th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.74 KB | None | 0 0
  1. {==============================================================================]  
  2.   Explanation: Returns the string before LAST s in str.                  
  3. [==============================================================================}
  4. function LastBefore(s, str: string): string;
  5. var
  6.   l, p, lp: Integer;
  7. begin
  8.   l := Length(str);
  9.   if (Length(s) <= l) then
  10.   begin
  11.     repeat
  12.       p := PosEx(s, str, (p + 1));
  13.       if (p > 0) then
  14.         lp := p;
  15.     until (p <= 0);
  16.     if (lp > 0) then
  17.       Result := Copy(str, 1, (lp - 1))
  18.     else
  19.       Result := '';
  20.   end else
  21.     Result := '';
  22. end;
  23.  
  24. var
  25.   str: string;
  26.  
  27. begin
  28.   ClearDebug;
  29.   str := 'LastBefore() WORKS! WORKS? Right?! ;)';
  30.   WriteLn(LastBefore(' WORK', str));
  31. end.
Advertisement
Add Comment
Please, Sign In to add comment