This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Empty string" – news ·newspapers ·books ·scholar ·JSTOR(November 2009) (Learn how and when to remove this message) |
Informal language theory, theempty string, also known as theempty word ornull string, is the uniquestring of length zero.
Formally, a string is a finite, ordered sequence ofcharacters such as letters, digits or spaces. The empty string is the special case where the sequence has length zero, so there are no symbols in the string.There is only one empty string, because two strings are only different if they have different lengths or a different sequence of symbols.In formal treatments,[1] the empty string is denoted withε or sometimesΛ orλ.
The empty string should not be confused with the empty language∅, which is aformal language (i.e. a set of strings) that contains no strings, not even the empty string.
The empty string has several properties:
Incontext-free grammars, aproduction rule that allows asymbol to produce the empty string is known as an ε-production, and the symbol is said to be "nullable".
In mostprogramming languages, the term "string" often refers to instances of adata type and thus they're a concept distinct from the one in the formal theory. Such strings are typically stored at distinctmemory addresses (locations) and thus have an identity. Thus, representatives of the same formal string (e.g., the empty string) may be stored in two or more places in memory and they can be taken as names of the formal empty string.
In this way, there could be multiple representatives of the empty string in memory, in contrast with the formal theory definition, for which there is only one possible empty string. However, a "string comparison function" would indicate that all of these representatives are equal to each other.
Even a string of length zero can require memory to store it, depending on the format being used. In most programming languages, the empty string is distinct from anull reference (or null pointer) because a null reference points to no string at all, not even the empty string.The empty string is a legitimate string, upon which most string operations should work. Some languages treat some or all of the following in similar ways: empty strings, null references, the integer 0, the floating point number 0, the Boolean valuefalse, theASCII characterNUL, or other such values.
The empty string is usually represented similarly to other strings. In implementations with string terminating character (null-terminated strings or plain text lines), the empty string is indicated by the immediate use of this terminating character.
Different functions, methods, macros, oridioms exist for checking if a string is empty in different languages.[example needed]
| λ representation | Programming languages |
|---|---|
"" | C,C#,C++,Go,Haskell,Java,JavaScript,Julia,Lua,M,Objective-C (as a C string),OCaml,Perl,PHP,PowerShell,Python,Ruby,Scala,Standard ML,Swift,Tcl,Visual Basic .NET |
'' | APL,Delphi,JavaScript,Lua,MATLAB,Pascal,Perl,PHP,PowerShell,Python,R,Ruby,Smalltalk,SQL |
character(0) | R[3] |
{'\0'} | C,C++,Objective-C (as a C string) |
new String() (fromjava.lang.String) | Java |
string() (fromstd::string) | C++ |
""s | C++ (since the2014 standard) |
@"" | Objective-C (as a constantNSString object) |
[NSString string] | Objective-C (as a newNSString object) |
q(), qq() | Perl |
str()[4]""""""r""u"" | Python |
%{}%() | Ruby |
String::new() (fromstd::string::String)[5] | Rust |
String.Empty (fromSystem.String) | C#,Visual Basic .NET |
String.make 0 '-' | OCaml |
{} | Tcl |
[[]] | Lua |
“”
| PowerShell |
.byte 0
| A64 |
This sectionneeds expansion. You can help byadding missing information.(March 2010) |
The empty string is a syntactically valid representation ofzero inpositional notation (in any base), which does not containleading zeros. Since the empty string does not have a standard visual representation outside of formal language theory, the number zero is traditionally represented by a singledecimal digit0 instead.
Zero-filled memory area, interpreted as anull-terminated string, is an empty string.
Empty lines of text show the empty string. This can occur from two consecutiveEOLs, as often occur intext files. This is sometimes used intext processing to separateparagraphs, e.g. inMediaWiki.
"".character(0) creates empty character vectors, which will output 0 when counted.PowerShell treats smart quotation marks, also called typographic or curly quotes, as normal quotation marks for strings. Don't use smart quotation marks to enclose strings.
"Hello, world„ is valid. Guillemets are not supported. Note that the German-style low single quotation mark given here isU+201A ‚SINGLE LOW-9 QUOTATION MARK; the similar-looking characterU+002C ,COMMA does not function as a quotation mark. PowerShell's official documentation recommends using straight quotation marks.[6]