Janilabo Posted May 22, 2012 Share Posted May 22, 2012 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] Quote Link to comment Share on other sites More sharing options...