'String is the representation of a sequence of characters (Chars). It is represented between single quotes. It can also be contatenated with +


  MyString: String;
  MyString := 'Hello';
  MyString := MyString + ' World';

String TypesEdit

  • ShortString (255 characters, up to 256 bytes of memory)
  • AnsiString (also called LongString) (~2^31 characters, up to to 2GB of memory)
  • UnicodeString (~2^30 wide characters, up to 1GB of memory)
  • WideString (~2^30 wide characters, up to 1GB of memory)

AnsiString was the current default for String until Delphi 2009, in which String defaults to UnicodeString.

Notes (from the Newsgroups)Edit

In a newsgroup discussion (comp.lang.pascal.delphi.misc early 2007), the question was raised how many stringtypes delphi has.

The one asking of course (me) knew there were more than the usual one-three that are usually named; short,ansi and widestring.

Note that in the summary below one can argue about the exact definition of a stringtype or if a certain entry counts as 1 or 255 (e.g. since shortstrings of a certain length are incompatible with eachother in some ways, one could say there are 255 shortstring types).

This however was not the purpose of the discussion. The purpose of the discussion is to make people aware about the vast amounts of stringtypes and conversions between them that exist in Delphi.

The original definition of a string type is: "Delphi string types and types that auto converted to them in some form or the other"

The list is:

  • 3 short,ansi,widestring types.
  • 1 (ansi)char
  • 1 wide char, (both = resp. char and widechar from now on)
  • 2 (static) array of both
  • 2 dynamic array of both.
  • 2 open array of both,
  • 2 pointer to both,
  • 2 pointer to array of both ,
1 open array shortstring. (in some semantic contexts different)

 16 ->Theoretic maximal number of conversions: 16*16 = 256

This is way too high of course:

  • assumes every conversion is possible (some like open arrays are possibly readonly),
  • assumes very conversion reversable.
  • also 16 direct assignments to same type are included, which are less prone to automatic
  conversion problems.

Some other remarks gathered from the various comments (IRC and c.l.p.delphi.misc)

  • Note that this even does not include some of these types in variants.
  • multibyte forms in existing stringtypes are not counted.
  • literals. Are string literals different ?
    • Are there more types of literals? (resourcestring a separate kind?)
    • are there conversions, not over the base string types between literals and e.g. static array of char?

The original list was created in a discussion about adding a new feature to FPC (and he also wanted to propose it to the Delphi devels). Among others, the "feature" added an autoconversion to strings. We asked "which string?". He answered "all of them".....