- Empty string
-
In computer science and formal language theory, the empty string (or null string)[1] is the unique string of length zero. It is denoted with λ or sometimes Λ or ε.
The empty string is distinct from a null reference in that in an object-oriented programming language a null reference to a string type doesn't point to a string object and will cause an error were one to try to perform any operation on it. The empty string is still a string upon which string operations may be attempted. Some languages however, may treat empty and null strings the same, e.g. if they use COM's strings.
A related concept is the empty language ∅, a formal language that contains no strings.
Contents
Properties
When present in a formal language, empty strings have several properties:
- . The string length is zero.
- . Under concatenation, the empty string is the identity element of the free monoid on the alphabet Σ.
- . Reversal of the empty string produces the empty string.
- The empty string precedes any other string in the lexicographical order.[2]
These properties may hold in some programming languages, but this is left up[citation needed] to the particular implementation.
Representations
The empty string usually represented in a way not different from a generic string. In implementations with string terminating character (C strings or plain text lines) it is just this terminating character placed to the first position.
λ representation Programming languages ""
C, C++, Perl, Python, C#, Go, PHP, Visual Basic .NET, Java, Turing, JavaScript, Haskell, Objective Caml, Tcl ''
Perl, PHP, Python, JavaScript, Delphi, Pascal {'\0'}
C, C++ std::string()
C++ @""
Objective-C qw()
Perl """"""
str()
Python string.Empty
C# String.Empty
Visual Basic .NET String.make 0 '-'
Objective Caml {}
Tcl Occurrence
The empty string is a syntactically valid representation of zero in positional notation (in any base), which does not contain leading zeros. Because handling of empty strings is problematical (particularly in a graphic environment), the zero number traditionally represented by one decimal digit 0 instead.
Zero-filled memory area, interpreted as a C string, is an empty string.
Empty lines (say, two consecutive EOLs) often occurred in text files and sometimes used in text processing to separate paragraphs, e.g. in MediaWiki.
See also
References
- ^ Kernighan and Ritchie, C, p. 38
- ^ CSE1002 Lecture Notes - Lexicographic
Null character · Null device · Null function · Null Object pattern · Null pointer · Null in SQL · Null stringSee also: Null coalescing operator · Nullable type · Undefined value Categories:- Formal languages
- String (computer science)
- Zero
- Formal methods stubs
Wikimedia Foundation. 2010.