Jump to content
Janilabo

LastBefore

Recommended Posts

Returns the text before last S in STR. Example included.

 

LastBefore

[scar]function LastBefore(s, str: string): string;

var

l, p, lp: Integer;

begin

l := Length(str);

if (Length(s) > l) then

Exit;

repeat

p := PosEx(s, str, (p + 1));

if (p > 0) then

lp := p;

until (p <= 0);

if (lp > 0) then

Result := Copy(str, 1, (lp - 1));

end;

 

var

str: string;

 

begin

ClearDebug;

str := 'LastBefore() WORKS! WORKS? Right?! ;)';

WriteLn(LastBefore(' WORK', str));

end.[/scar]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...