# Empty string

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Empty_string
> Markdown URL: https://mediated.wiki/source/Empty_string.md
> Source: https://en.wikipedia.org/wiki/Empty_string
> Source revision: 1350342059
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

"""" redirects here. For the printed character, see [Quotation mark](/source/Quotation_mark).

Unique string of length zero

This article needs additional citations for verification. Please help improve this article by adding 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)

In [formal language theory](/source/Formal_language_theory), the **empty string**, also known as the **empty word** or **null string**, is the unique [string](/source/String_(computer_science)) of length zero.

## Formal theory

Formally, a string is a finite, ordered sequence of [characters](/source/Character_(symbol)) 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 **[ε](/source/%CE%95)** or sometimes **[Λ](/source/%CE%9B)** or **[λ](/source/%CE%9B)**.

The empty string should not be confused with the empty language [∅](/source/%E2%88%85), which is a [formal language](/source/Formal_language) (i.e. a set of strings) that contains no strings, not even the empty string.

The empty string has several properties:

- |ε| = 0. Its [string length](/source/String_(computer_science)#Formal_theory) is zero.

- ε ⋅ s = s ⋅ ε = s. The empty string is the [identity element](/source/Identity_element) of the [concatenation](/source/Concatenation) operation. The set of all strings forms a [free monoid](/source/Free_monoid) with respect to ⋅ and ε.

- εR = ε. Reversal of the empty string produces the empty string, so the empty string is a [palindrome](/source/Palindrome).

- ∀ c ∈ s : P ( c ) {\displaystyle \forall c\in s:P(c)} . Statements that are about all characters in a string are [vacuously true](/source/Vacuous_truth).

- The empty string precedes any other string under [lexicographical order](/source/Lexicographical_order), because it is the shortest of all strings.[2]

In [context-free grammars](/source/Context-free_grammar), a [production rule](/source/Production_(computer_science)) that allows a [symbol](/source/Symbol_(logic)) to produce the empty string is known as an ε-production, and the symbol is said to be "nullable".

## Use in programming languages

In most [programming languages](/source/Programming_language), the term "string" often refers to instances of a [data type](/source/Data_type) and thus they're a concept distinct from the one in the formal theory. Such strings are typically stored at distinct [memory addresses](/source/Memory_address) (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 a [null reference](/source/Null_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 value [false](/source/False_(logic)), the [ASCII](/source/ASCII) character [NUL](/source/Null_character), or other such values.

The empty string is usually represented similarly to other strings. In implementations with string terminating character ([null-terminated strings](/source/Null-terminated_string) or plain text lines), the empty string is indicated by the immediate use of this terminating character.

Different functions, methods, macros, or [idioms](/source/Programming_idiom) exist for checking if a string is empty in different languages.[*[example needed](https://en.wikipedia.org/wiki/Wikipedia:AUDIENCE)*]

λ 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() (from java.lang.String or System.String) Java, C# string() (from 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()[4] """""" r"" u"" Python %{} %() Ruby String::new() (from std::string::String)[5] Rust String.Empty (from System.String) C#, Visual Basic .NET String.make 0 '-' OCaml {} Tcl [[]] Lua “” ‘’ „” ‚‘[7] PowerShell .byte 0 .ascii "" .asciz "" A64

### Representations of the empty string

This section needs expansion. You can help by adding missing information. (March 2010)

The empty string is a syntactically valid representation of [zero](/source/Zero) in [positional notation](/source/Positional_notation) (in any base), which does not contain [leading zeros](/source/Leading_zero). Since the empty string does not have a standard visual representation outside of formal language theory, the number zero is traditionally represented by a single [decimal digit](/source/Decimal_digit) **0** instead.

Zero-filled memory area, interpreted as a [null-terminated string](/source/Null-terminated_string), is an empty string.

Empty lines of text show the empty string. This can occur from two consecutive [EOLs](/source/End_of_line), as often occur in [text files](/source/Text_file). This is sometimes used in [text processing](/source/Text_processing) to separate [paragraphs](/source/Paragraph), e.g. in [MediaWiki](/source/MediaWiki).

## See also

- [Empty set](/source/Empty_set)

- [Null-terminated string](/source/Null-terminated_string)

- [Concatenation theory](/source/Concatenation_theory)

- [String literal](/source/String_literal)

## References

1. **[^](#cite_ref-1)** Corcoran, John; Frank, William; Maloney, Michael (1974). "String theory". *Journal of Symbolic Logic*. **39** (4): 625–637. [doi](/source/Doi_(identifier)):[10.2307/2272846](https://doi.org/10.2307%2F2272846). [JSTOR](/source/JSTOR_(identifier)) [2272846](https://www.jstor.org/stable/2272846). [S2CID](/source/S2CID_(identifier)) [2168826](https://api.semanticscholar.org/CorpusID:2168826).

1. **[^](#cite_ref-2)** ["CSE1002 Lecture Notes – Lexicographic"](https://web.archive.org/web/20091229212044/http://cs.fit.edu/~ryan/cse1002/lectures/lexicographic.pdf) (PDF). Archived from [the original](http://cs.fit.edu/~ryan/cse1002/lectures/lexicographic.pdf) (PDF) on 2009-12-29. Retrieved 2010-03-27.

1. **[^](#cite_ref-3)** There are two ways to create "empty strings" in R; the other is listed here as "". character(0) creates empty character vectors, which will output 0 when counted.

1. **[^](#cite_ref-4)** Another way to make an empty string is multiplying a string by 0 or a negative integer.

1. **[^](#cite_ref-5)** ["String in std::string - Rust"](https://doc.rust-lang.org/std/string/struct.String.html#method.new). *doc.rust-lang.org*. Retrieved 2022-11-30.

1. **[^](#cite_ref-6)** ["about_Quoting_Rules – PowerShell"](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.5). *Microsoft Learn*. [Archived](https://web.archive.org/web/20250814175659/https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.5) from the original on 2025-08-14. Retrieved 26 August 2025. 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.

1. **[^](#cite_ref-7)** All 'smart' quotation marks work as both opening and closing marks in any combination, except that single marks must be paired with single marks and double marks with double marks. For example "Hello, world„ is valid. Guillemets are not supported. Note that the German-style low single quotation mark given here is U+201A ‚ SINGLE LOW-9 QUOTATION MARK; the similar-looking character U+002C , COMMA does not function as a quotation mark. PowerShell's official documentation recommends using straight quotation marks.[6]

---
Adapted from the Wikipedia article [Empty string](https://en.wikipedia.org/wiki/Empty_string) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Empty_string?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
