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...
, 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
- Introduction To Java – MFC 158 G . · 1786834800.0
- RCA 301 Electronic Data Processing System - Programmers' Reference Manual . · 1786834800.0
- Wearmouth, Geoff. An Assembly Listing of the ROM of the Sinclair ZX80 . · 1786834800.0
- Allison, Dennis. Design Notes for Tiny BASIC . · 1786834800.0
- Charles Crowley. [http://www.cs.unm.edu/~crowley/papers/sds.pdf "Data Structures for Text Sequences"] webarchive|url=https://web.archive.org/web/20160304042917/https://www.cs.unm.edu/~crowley/papers . · 1786834800.0
- [https://www.sudo.ws/todd/papers/strlcpy.html "strlcpy and strlcat - consistent, safe, string copy and concatenation."] webarchive|url=https://web.archive.org/web/20160313163321/https://www.sudo.ws/ . · 1786834800.0
- [http://udel.edu/~pconrad/UnixAtUD/strcpy.html "A rant about strcpy, strncpy and strlcpy."] webarchive|url=https://web.archive.org/web/20160229080205/http://udel.edu/~pconrad/UnixAtUD/strcpy.html |d . · 1786834800.0
- The Prague Stringology Club . stringology.org . retrieved 23 May 2015 · 1786834800.0
- Evarts, Holly. Former Dean Zvi Galil Named a Top 10 Most Influential Computer Scientist in the Past Decade . · 1786834800.0
- Essential Perl . · 1786834800.0
- x86 string instructions . · 1786834800.0
- de St. Germain, H. James. Strings . University of Utah, Kahlert School of Computing . · 1786834800.0
- John E. Hopcroft, Jeffrey D. Ullman. Introduction to Automata Theory, Languages, and Computation . Addison-Wesley . 1979. · 1786834800.0
- DNA as a Biochemical Entity and Data String . November 14, 2019. · 1786834800.0
- string (n.) . Online Etymology Dictionary . · 1786834800.0
- Lewis, C.I. A survey of symbolic logic . University of California Press . 1918. · 1786834800.0
- Sammet, Jean E. Programming Languages: . · 1786834800.0
- IBM System/360 Operating System - PL/I (F) - Programmer's Guide - Program Number 360S-NL-5ll . November 1968. · 1786834800.0
- Computer Systems: A Programmer's Perspective . · 1786834800.0
- RCA 501 Electronic Data Processing System - Programmers' Reference Manual . · 1786834800.0
Cite this
"String (computer science)". 1786846121. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1369630256