DelphiBasics
LastDelimiter
Function
Find the last position of selected characters in a string SysUtils unit
 function LastDelimiter(const Delimiters, Source string):Integer;
Description
The LastDelimiter function finds the last occurence of any of a set of Delimiter characters in a Source string.
 
If found, the position is returned. Otherwise, 0 is returned.
Notes
Strings start with 1 as the first character.
Related commands
AnsiPosFind the position of one string in another
StrScanSearches for a specific character in a constant string
 Download this web site as a Windows program.




 
Example code : Find the last position of 1 or more characters in a string
var
  source, find : string;
  position     : Integer;

begin
  // Create a string
  source := '12345678901234567890';

  // Find the position of the last 1
  position := LastDelimiter('1', source);
  ShowMessage('The last 1 is at '+IntToStr(position));

  // Find the position of the last 2, 4 or 6
  position := LastDelimiter('246', source);
  ShowMessage('The last 2, 4 or 6 is at '+IntToStr(position));
end;
Show full unit code
  The last 1 is at 11
  The last 2, 4 or 6 is at 16
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page