Jump to content

Empty string

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 103.151.0.36 (talk) at 13:15, 3 August 2021 (All deleted). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In formal language theory, the empty string, or empty word, is the unique string of length zero.

Clear all

Use in programming languages

In most programming languages, strings are a data type. Strings are typically stored at distinct memory locations. This means that the same string (for example, the empty string) could be stored in two or more places in memory.

In this way there could be multiple empty strings 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 empty strings 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 a null reference (or null pointer) because a null reference does not point to any 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 value false, the ASCII character NUL, 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.

λ representation Programming languages
"" C, C#, C++, Go, Haskell, Java, JavaScript, Julia, Lua, M, Objective-C (as a C string), OCaml, Perl, PHP, Python, Ruby, Scala, Standard ML, Swift, Tcl, Visual Basic .NET
'' APL, Delphi, JavaScript, Matlab, Pascal, Perl, PHP, Python, Ruby, Smalltalk, SQL
{'\0'} C, C++, Objective-C (as a C string)
std::string() C++
""s C++ (since the 2014 standard)
@"" Objective-C (as a constant NSString object)
[NSString string] Objective-C (as a new NSString object)
q(), qq() Perl
str() Python
%{}
%()
Ruby
string.Empty C#, Visual Basic .NET
String.make 0 '-' OCaml
{} Tcl
[[]] Lua

Deleted all

See also

References