In formal language theory, the
empty string, or
empty word, is the unique cord of length zero.
Formally, a string is a finite, ordered sequence of characters such equally messages, digits or spaces. The empty string is the special case where the sequence has length nada, so there are no symbols in the string. In that location is simply i empty string, because two strings are merely different if they have different lengths or a dissimilar sequence of symbols. In formal treatments,[ane]
the empty cord is denoted with
The empty string should not be dislocated with the empty language ∅, which is a formal language (i.e. a ready of strings) that contains no strings, not even the empty string.
The empty string has several properties:
- |ε| = 0. Its string length is nil.
- ε ⋅ s = due south ⋅ ε = s. The empty string is the identity chemical element of the concatenation operation. The set of all strings forms a free monoid with respect to ⋅ and ε.
= ε. Reversal of the empty string produces the empty string.
- The empty string precedes whatsoever other string under lexicographical order, because information technology is the shortest of all strings.
In context-complimentary grammars, a production rule that allows a symbol to produce the empty string is known as an ε-production, and the symbol is said to be “nullable”.
Use in programming languages
In nearly programming languages, strings are a data type. Strings are typically stored at singled-out memory addresses (locations). Thus, the aforementioned cord (for example, the empty string) may be stored in two or more than places in memory.
In this way, there could exist multiple empty strings in retentivity, in contrast with the formal theory definition, for which in that location is only 1 possible empty string. However, a string comparison office would betoken that all of these empty strings are equal to each other.
Even a cord of length zippo can crave memory to store it, depending on the format being used. In most programming languages, the empty string is distinct from a naught reference (or zero pointer) because a cypher reference points to no string at all, not fifty-fifty the empty cord. The empty string is a legitimate string, upon which most cord operations should work. Some languages treat some or all of the following in like ways: empty strings, null references, the integer 0, the floating signal number 0, the Boolean value false, the ASCII graphic symbol NUL, or other such values.
The empty cord is usually represented similarly to other strings. In implementations with string terminating graphic symbol (zippo-terminated strings or apparently text lines), the empty cord is indicated by the immediate use of this terminating graphic symbol.
|λ representation||Programming languages|
||C, C++, Objective-C (as a C string)|
||C++ (since the 2014 standard)|
||Objective-C (as a constant
||Objective-C (as a new
||C#, Visual Bones .Internet|
Examples of empty strings
The empty string is a syntactically valid representation of zero in positional notation (in any base), which does non contain leading zeros. Since the empty string does non have a standard visual representation exterior of formal language theory, the number goose egg is traditionally represented past a single decimal digit
Nada-filled memory area, interpreted as a aught-terminated string, is an empty string.
Empty lines of text show the empty string. This can occur from two consecutive EOLs, as often occur in text files, and this is sometimes used in text processing to separate paragraphs, e.g. in MediaWiki.
See as well
- Empty prepare
- Zero-terminated string
- Concatenation theory
Corcoran, John; Frank, William; Maloney, Michael (1974). “String theory”.
Periodical of Symbolic Logic.
(4): 625–637. doi:10.2307/2272846. JSTOR 2272846.
CSE1002 Lecture Notes – Lexicographic
At that place are two ways to create “empty strings” in R; the other is listed here every bit
creates empty character vectors, which will output 0 when counted.