
Of course, even variable-length strings are limited in length – by the size of available computer memory. Most strings in modern programming languages are variable-length strings. In general, there are two types of string datatypes: fixed-length strings, which have a fixed maximum length to be determined at compile time and which use the same amount of memory whether this maximum is needed or not, and variable-length strings, whose length is not arbitrarily fixed and which can use varying amounts of memory depending on the actual requirements at run time (see Memory management). The syntax of most high-level programming languages allows for a string, usually quoted in some way, to represent an instance of a string datatype such a meta-string is called a literal or string literal.Īlthough formal strings can have an arbitrary finite length, the length of strings in real languages is often constrained to an artificial maximum. In some languages they are available as primitive types and in others as composite types. Strings are such an important and useful datatype that they are implemented in nearly every programming language. See also: Comparison of programming languages (string functions)Ī string datatype is a datatype modeled on the idea of a formal string. In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set called an alphabet. When a string appears literally in source code, it is known as a string literal or an anonymous string. String may also denote more general arrays or other sequence (or list) data types and structures.ĭepending on the programming language and precise data type used, a variable declared to be a string may either cause storage in memory to be statically allocated for a predetermined maximum length or employ dynamic allocation to allow it to hold a variable number of elements.


A string is generally considered as a data type and is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding.

The latter may allow its elements to be mutated and the length changed, or it may be fixed (after creation). In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. They are useful for storing human-readable data, like sentences, or lists of alphabetical data, like the nucleic acid sequences of DNA.
