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 |
$LongStrings |
|
Treat string types as AnsiString or ShortString |
AnsiCompareStr |
|
Compare two strings for equality |
AnsiLowerCase |
|
Change upper case characters in a string to lower case |
AnsiPos |
|
Find the position of one string in another |
AnsiString |
|
A data type that holds a string of AnsiChars |
AnsiUpperCase |
|
Change lower case characters in a string to upper case |
Concat |
|
Concatenates one or more strings into one string |
Copy |
|
Create a copy of part of a string or an array |
Delete |
|
Delete a section of characters from a string |
Length |
|
Return the number of elements in an array or string |
Move |
|
Copy bytes of data from a source to a destination |
PShortString |
|
A pointer to an ShortString value |
SetLength |
|
Changes the size of a string, or the size(s) of an array |
String |
|
A data type that holds a string of characters |
WideString |
|
A data type that holds a string of WideChars |
|
|
|
|
Example code : Assigning to a ShortString and a fixed length 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 // The System unit does not need to be defined 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
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; end.
|
Hide full unit code |
smallString size = 3
smallString = AB
smallishString size = 256
smallishString = ABCD
|
|