Janilabo

Janilabo | LastBefore() [Simba]

Jun 21st, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.43 KB | None | 0 0
  1. function LastBefore(s, str: string): string;
  2. var
  3.   l, p, lp: Integer;
  4. begin
  5.   l := Length(str);
  6.   if (Length(s) > l) then
  7.     Exit;
  8.   repeat
  9.     p := PosEx(s, str, (p + 1));
  10.     if (p > 0) then
  11.       lp := p;
  12.   until (p <= 0);
  13.   if (lp > 0) then
  14.     Result := Copy(str, 1, (lp - 1));
  15. end;
  16.  
  17. var
  18.   str: string;
  19.  
  20. begin
  21.   ClearDebug;
  22.   str := 'LastBefore() WORKS! WORKS? Right?! ;)';
  23.   WriteLn(LastBefore(' WORK', str));
  24. end.
Advertisement
Add Comment
Please, Sign In to add comment