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 |
AnsiPos |
|
Find the position of one string in another |
StrScan |
|
Searches for a specific character in a constant string |
|
|
|
|
Example code : Find the last position of 1 or more characters in a string |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses SysUtils, // Unit containing the LastDelimiter command Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); 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; end.
|
Hide full unit code |
The last 1 is at 11
The last 2, 4 or 6 is at 16
|
|