DelphiBasics
ShortString
Type
Defines a string of up to 255 characters System unit
type ShortString
Description
The ShortString type holds sequences of characters up to 255 in length.
 
Strings can be assigned from other strings, from functions that return a string, and with concatenations as in the sample code.
Notes
ShortStrings are indexed with 1 for the first character (arrays start with 0 for the first element).

A String type is treated as a ShortString when the $LongStrings compiler directive is set to Off
Related commands
$LongStringsTreat string types as AnsiString or ShortString
AnsiCompareStrCompare two strings for equality
AnsiLowerCaseChange upper case characters in a string to lower case
AnsiPosFind the position of one string in another
AnsiStringA data type that holds a string of AnsiChars
AnsiUpperCaseChange lower case characters in a string to upper case
ConcatConcatenates one or more strings into one string
CopyCreate a copy of part of a string or an array
DeleteDelete a section of characters from a string
LengthReturn the number of elements in an array or string
MoveCopy bytes of data from a source to a destination
PShortStringA pointer to an ShortString value
SetLengthChanges the size of a string, or the size(s) of an array
StringA data type that holds a string of characters
WideStringA data type that holds a string of WideChars
 Download this web site as a Windows program.




 
Example code : Assigning to a ShortString and a fixed length string
var
  smallString    : string[2];
  smallishString : ShortString;

begin
  // Assign to our small string
  smallString := 'ABCD';
  ShowMessageFmt('smallString size = %d',[SizeOf(smallString)]);
  ShowMessageFmt('smallString = %s',[smallString]);

  // Assign to our slightly bigger string
  smallishString := 'ABCD';
  ShowMessageFmt('smallishString size = %d',[SizeOf(smallishString)]);
  ShowMessageFmt('smallishString = %s',[smallishString]);
end;
Show full unit code
  smallString size = 3
  smallString = AB
  smallishString size = 256
  smallishString = ABCD
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page