DelphiBasics
AnsiMidStr
Function
Returns a substring from the middle characters of a string StrUtils unit
 function AnsiMidStr(const Source AnsiString; const Start, Count Integer):AnsiString;
Description
The AnsiMidStr returns a string comprising a sequence of characters from a source string.
 
It attempts to return Count characters from position Start of the Source.
 
If Count exceeds the remaining size of the source, the whole of the remainder of the source is returned.
Notes
Strings start with index = 1 (arrays start with 0)
Related commands
AnsiLeftStrExtracts characters from the left of a string
AnsiRightStrExtracts characters from the right of a string
TrimRemoves leading and trailing blanks from a string
TrimLeftRemoves leading blanks from a string
TrimRightRemoves trailing blanks from a string
 Download this web site as a Windows program.




 
Example code : A simple example
var
  source, target : AnsiString;
begin
  source := '123456789';
  target := AnsiMidStr(source, 2, 4);

  ShowMessage('Source = '+source);
  ShowMessage('Target = '+target);
end;
Show full unit code
  Source = 123456789
  Target = 2345
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page