encyclopegia.org

String (computer science)

, and are often used to store human-readable data, such as words or sentences. In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed (after creation). A string is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. More general, string may also denote a sequence (or list) of data other than just characters. Depending 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. When a string appears literally in source code, it is known as a string literal or an anonymous 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.

, and are often used to store human-readable data, such as words or sentences. In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and the length changed, or it may be fixed (after creation). A string is often implemented as an array data structure of bytes (or words) that stores a sequence of elements, typically characters, using some character encoding. More general, string may also denote a sequence (or list) of data other than just characters. Depending 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. When a string appears literally in source code, it is known as a string literal or an anonymous 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. Computer settings or parameters, like " ?action=edit " as a URL query string. Often these are intended to be somewhat human-readable, though their primary purpose is to communicate to computers. The term string may also designate a sequence of data or computer records other than characters, like a "string of bits", but when used without qualification it refers to strings of characters. ==History== Use of the word "string" to mean any items arranged in a line, series or succession dates back centuries. In 19th-century typesetting, compositors used the term "string" to denote a length of type printed on paper; the string would be measured to determine the compositor's pay. Use of the word "string" to mean "a sequence of symbols or linguistic elements in a definite order" emerged from mathematics, symbolic logic, and linguistic theory to speak about the formal behavior of symbolic systems, setting aside the symbols' meaning. For example, logician C. I. Lewis wrote in 1918: A mathematical system is any set of strings of recognisable marks in which some of the strings are taken initially and the remainder derived from these by operations performed according to rules which are independent of any meaning assigned to the marks. That a system should consist of 'marks' instead of sounds or odours is immaterial. According to Jean E. Sammet, "the first realistic string handling and pattern matching language" for computers was COMIT in the 1950s, followed by the SNOBOL language of the early 1960s. public final class String { private unsigned long length; // string length private UniquePointer text; // explicit ownership // public methods... } However, since the implementation is usually hidden, the string must be accessed and modified through member functions. text is a pointer to a dynamically allocated memory area, which might be expanded as needed. See also string (C++). Let \Sigma be a finite set of distinct, unambiguous symbols (alternatively called characters), called the alphabet. A string (or word or expression ) over \Sigma is any finite sequence of symbols from \Sigma . For example, if \Sigma = \{\texttt{0}, \texttt{1}\} , then \texttt{01011} is a string over \Sigma . The length of a string s is the number of symbols in s (the length of the sequence) and can be any non-negative integer; it is often denoted as |s| . The empty string is the unique string over \Sigma of length 0 , and is denoted \varepsilon or \lambda . The set of all strings over \Sigma of length n is denoted \Sigma^n . For example, if \Sigma = \{\texttt{0}, \texttt{1}\} , then \Sigma^2 = \{\texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}\} . We have \Sigma^0 = \{\varepsilon\} for every alphabet \Sigma . The set of all strings over \Sigma of any length is the Kleene closure of \Sigma and is denoted \Sigma^* . In terms of \Sigma^n , \Sigma^{*} = \bigcup_{n = 0}^\infty \Sigma^{n} For example, if \Sigma = \{\texttt{0}, \texttt{1}\} , then \Sigma^* = \{\varepsilon, \texttt{0}, \texttt{1}, \texttt{00}, \texttt{01}, \texttt{10}, \texttt{11}, \texttt{000}, \texttt{001}, \texttt{010}, \texttt{011}, ...\} . Although the set \Sigma^* itself is countably infinite, each element of \Sigma^* is a string of finite length. A set of strings over \Sigma (i.e. any subset of \Sigma^* ) is called a formal language over \Sigma . For example, if \Sigma = \{\texttt{0}, \texttt{1}\} , the set of strings with an even number of zeros, \{\varepsilon, \texttt{1}, \texttt{00}, \texttt{11}, \texttt{001}, \texttt{010}, \texttt{100}, \texttt{111}, \texttt{0000}, \texttt{0011}, \texttt{0101}, \texttt{0110}, \texttt{1001}, \texttt{1010}, \texttt{1100}, \texttt{1111}, ...\} , is a formal language over \Sigma . Concatenation is an important binary operation on \Sigma^* . For any two strings s and t in \Sigma^* , their concatenation is defined as the sequence of symbols in s followed by the sequence of characters in t , and is denoted st . For example, if \Sigma = \{\texttt{a}, \texttt{b}, ..., \texttt{z}\} (i.e. the lowercase English alphabet), s = \texttt{bear} , and t = \texttt{hug} , then st = \texttt{bearhug} and ts = \texttt{hugbear} . String concatenation is an associative, but non-commutative operation. The empty string \varepsilon serves as the identity element; for any string s , \varepsilon s = s \varepsilon = s . Therefore, the set \Sigma^* and the concatenation operation form a monoid, the free monoid generated by \Sigma . In addition, the length function defines a monoid homomorphism from \Sigma^* to the non-negative integers (that is, a function L: \Sigma^{*} \mapsto \mathbb{N} \cup \{0\} , such that L(st)=L(s)+L(t)\quad \forall s,t\in\Sigma^* ). A string s is said to be a substring or factor of t if there exist (possibly empty) strings u and v such that t = usv . The relation "is a substring of" defines a partial order on \Sigma^* , the least element of which is the empty string. A string s is said to be a prefix of t if there exists a string u such that t = su . If u is nonempty, s is said to be a proper prefix of t . Symmetrically, a string s is said to be a suffix of t if there exists a string u such that t = us . If u is nonempty, s is said to be a proper suffix of t . Suffixes and prefixes are substrings of t . Both the relations "is a prefix of" and "is a suffix of" are prefix orders. The reverse of a string is a string with the same symbols but in reverse order. For example, if s = \texttt{abc} (where \texttt{a} , \texttt{b} , and \texttt{c} are symbols of the alphabet), then the reverse of s is \texttt{cba} . A string that is the reverse of itself (e.g., s = \texttt{madam} ) is called a palindrome, which also includes the empty string and all strings of length 1 . A string s = uv is said to be a rotation of t if t = vu . For example, if \Sigma = \{\texttt{0}, \texttt{1}\} the string \texttt{0011001} is a rotation of \texttt{0100110} , where u = \texttt{00110} and v = \texttt{01} . As another example, the string \texttt{abc} has three different rotations, viz. \texttt{abc} itself (with u=\texttt{abc} , v=\varepsilon ), \texttt{bca} (with u=\texttt{bc}, v=\texttt{a} ), and \texttt{cab} (with u=\texttt{c}, v=\texttt{ab} ). It is often useful to define an ordering on a set of strings. If the alphabet \Sigma has a total order (cf. alphabetical order) one can define a total order on \Sigma^* called lexicographical order. The lexicographical order is total if the alphabetical order is, but is not well-founded for any nontrivial alphabet, even if the alphabetical order is. For example, if \Sigma = \{\texttt{0}, \texttt{1}\} and \texttt{0} , then the lexicographical order on \Sigma^* includes the relationships \varepsilon With respect to this ordering, e.g. the infinite set \{ \texttt{1}, \texttt{01}, \texttt{001}, \texttt{0001}, \texttt{00001}, \texttt{000001}, ... \} has no minimal element. See Shortlex for an alternative string ordering that preserves well-foundedness. For the example alphabet, the shortlex order is \varepsilon ==Explanatory notes==

References

  1. Introduction To Java – MFC 158 G . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Introduction To Java – MFC 158 G ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Introduction To Java – MFC 158 G ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA encyclopegia.org. (2026). Introduction To Java – MFC 158 G . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  2. RCA 301 Electronic Data Processing System - Programmers' Reference Manual . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "RCA 301 Electronic Data Processing System - Programmers' Reference Manual ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "RCA 301 Electronic Data Processing System - Programmers' Reference Manual ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA encyclopegia.org. (2026). RCA 301 Electronic Data Processing System - Programmers' Reference Manual . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  3. Wearmouth, Geoff. An Assembly Listing of the ROM of the Sinclair ZX80 . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Wearmouth, Geoff. An Assembly Listing of the ROM of the Sinclair ZX80 ." Wearmouth, Geoff. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Wearmouth, Geoff. An Assembly Listing of the ROM of the Sinclair ZX80 ." Wearmouth, Geoff. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA Wearmouth, Geoff. (2026). Wearmouth, Geoff. An Assembly Listing of the ROM of the Sinclair ZX80 . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  4. Allison, Dennis. Design Notes for Tiny BASIC . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Allison, Dennis. Design Notes for Tiny BASIC ." Allison, Dennis. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Allison, Dennis. Design Notes for Tiny BASIC ." Allison, Dennis. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA Allison, Dennis. (2026). Allison, Dennis. Design Notes for Tiny BASIC . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  5. Data Structures for Text Sequences · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Data Structures for Text Sequences." Charles Crowley. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Data Structures for Text Sequences." Charles Crowley. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA Charles Crowley. (2026). Data Structures for Text Sequences. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  6. strlcpy and strlcat - consistent, safe, string copy and concatenation. · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "strlcpy and strlcat - consistent, safe, string copy and concatenation." https://www. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "strlcpy and strlcat - consistent, safe, string copy and concatenation." https://www. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA https://www. (2026). strlcpy and strlcat - consistent, safe, string copy and concatenation. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  7. A rant about strcpy, strncpy and strlcpy. · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "A rant about strcpy, strncpy and strlcpy." http://udel. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "A rant about strcpy, strncpy and strlcpy." http://udel. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA http://udel. (2026). A rant about strcpy, strncpy and strlcpy. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  8. The Prague Stringology Club . stringology.org . retrieved 23 May 2015 · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "The Prague Stringology Club . stringology.org . retrieved 23 May 2015." The Prague Stringology Club. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "The Prague Stringology Club . stringology.org . retrieved 23 May 2015." The Prague Stringology Club. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA The Prague Stringology Club. (2026). The Prague Stringology Club . stringology.org . retrieved 23 May 2015. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  9. Evarts, Holly. Former Dean Zvi Galil Named a Top 10 Most Influential Computer Scientist in the Past Decade . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Evarts, Holly. Former Dean Zvi Galil Named a Top 10 Most Influential Computer Scientist in the Past Decade ." Evarts, Holly. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Evarts, Holly. Former Dean Zvi Galil Named a Top 10 Most Influential Computer Scientist in the Past Decade ." Evarts, Holly. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA Evarts, Holly. (2026). Evarts, Holly. Former Dean Zvi Galil Named a Top 10 Most Influential Computer Scientist in the Past Decade . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  10. Essential Perl . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Essential Perl ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Essential Perl ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA encyclopegia.org. (2026). Essential Perl . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  11. x86 string instructions . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "x86 string instructions ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "x86 string instructions ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA encyclopegia.org. (2026). x86 string instructions . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  12. de St. Germain, H. James. Strings . University of Utah, Kahlert School of Computing . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "de St. Germain, H. James. Strings . University of Utah, Kahlert School of Computing ." de St. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "de St. Germain, H. James. Strings . University of Utah, Kahlert School of Computing ." de St. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA de St. (2026). de St. Germain, H. James. Strings . University of Utah, Kahlert School of Computing . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  13. John E. Hopcroft, Jeffrey D. Ullman. Introduction to Automata Theory, Languages, and Computation . Addison-Wesley . 1979. · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "John E. Hopcroft, Jeffrey D. Ullman. Introduction to Automata Theory, Languages, and Computation . Addison-Wesley . 1979." John E. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "John E. Hopcroft, Jeffrey D. Ullman. Introduction to Automata Theory, Languages, and Computation . Addison-Wesley . 1979." John E. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA John E. (2026). John E. Hopcroft, Jeffrey D. Ullman. Introduction to Automata Theory, Languages, and Computation . Addison-Wesley . 1979. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  14. DNA as a Biochemical Entity and Data String . November 14, 2019. · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "DNA as a Biochemical Entity and Data String . November 14, 2019." DNA as a Biochemical Entity and Data String. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "DNA as a Biochemical Entity and Data String . November 14, 2019." DNA as a Biochemical Entity and Data String. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA DNA as a Biochemical Entity and Data String. (2026). DNA as a Biochemical Entity and Data String . November 14, 2019. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  15. string (n.) . Online Etymology Dictionary . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "string (n.) . Online Etymology Dictionary ." string (n. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "string (n.) . Online Etymology Dictionary ." string (n. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA string (n. (2026). string (n.) . Online Etymology Dictionary . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  16. Lewis, C.I. A survey of symbolic logic . University of California Press . 1918. · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Lewis, C.I. A survey of symbolic logic . University of California Press . 1918." Lewis, C. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Lewis, C.I. A survey of symbolic logic . University of California Press . 1918." Lewis, C. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA Lewis, C. (2026). Lewis, C.I. A survey of symbolic logic . University of California Press . 1918. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  17. Sammet, Jean E. Programming Languages: . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Sammet, Jean E. Programming Languages: ." Sammet, Jean E. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Sammet, Jean E. Programming Languages: ." Sammet, Jean E. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA Sammet, Jean E. (2026). Sammet, Jean E. Programming Languages: . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  18. IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll . November 1968. · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll . November 1968." IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll . November 1968." IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll. 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll. (2026). IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll . November 1968. Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  19. Computer Systems: A Programmer's Perspective . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "Computer Systems: A Programmer's Perspective ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "Computer Systems: A Programmer's Perspective ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA encyclopegia.org. (2026). Computer Systems: A Programmer's Perspective . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

  20. RCA 501 Electronic Data Processing System - Programmers' Reference Manual . · retrieved 2026-08-15 · rev 1369630256
    Cite this reference

    MLA "RCA 501 Electronic Data Processing System - Programmers' Reference Manual ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256. Accessed 24 November 2026.

    Chicago "RCA 501 Electronic Data Processing System - Programmers' Reference Manual ." 2026-08-15. https://en.wikipedia.org/w/index.php?oldid=1369630256.

    APA encyclopegia.org. (2026). RCA 501 Electronic Data Processing System - Programmers' Reference Manual . Retrieved November 24, 2026, from https://en.wikipedia.org/w/index.php?oldid=1369630256

Cite this article

MLA

"String (computer science)." encyclopegia.org, 2026, https://encyclopegia.org/wiki/string-computer-science. Accessed 24 November 2026.

Chicago

"String (computer science)." encyclopegia.org. Accessed November 24, 2026. https://encyclopegia.org/wiki/string-computer-science.

APA

encyclopegia.org. (2026). String (computer science). Retrieved November 24, 2026, from https://encyclopegia.org/wiki/string-computer-science

Accessed November 24, 2026 · CC BY-SA 4.0 · citation page · JSON

Related articles

Politics of Namibia

enwiki · references available

Transport in Namibia

enwiki · references available

Nauru

enwiki · references available

Demographics of Nauru

enwiki · references available

Demographics of Nepal

enwiki · references available

Foreign relations of New Zealand

enwiki · references available

Tree (abstract data type)

enwiki · references available
CC BY-SA 4.0 · share-alike · https://en.wikipedia.org/w/index.php?oldid=1369630256 · 0.5 · snapshot enwiki-001369630256

Cite · JSON · Search

Related services and records

Services

  • Estate — measured countries, lanes and facts
  • Intel — live corroborated events
  • Legal — statutes, cases and citations
  • Encyclopedia — articles with inline sources
  • Space — launches, satellites and orbits
  • Search — federated search and reports
  • Pass — passport account and SSO
  • Corpora — read-only corpus origins
  • e01 — self-hosted corpora and tools

Text and metadata only; each target carries its own sources. Missing data is published as no-data, never estimated.