Content deleted Content added
Citation bot (talk | contribs) Add: s2cid. | Use this bot. Report bugs. | Suggested by Abductive | Category:Formal languages | #UCB_Category 51/202 |
Hairy Dude (talk | contribs) →Use in programming languages: more on PowerShell Tags: Mobile edit Mobile web edit Advanced mobile edit |
||
(31 intermediate revisions by 17 users not shown) | |||
Line 1:
{{
{{Short description|Unique string of length zero}}
{{Refimprove|date=November 2009}}
In [[formal language theory]], the '''empty string''',
==
Formally, a string is a finite, ordered sequence of [[character (symbol)|characters]] 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.
Line 14:
* |ε| = 0. Its [[string (computer science)#Formal theory|string length]] is zero.
* ε ⋅ s = s ⋅ ε = s. The empty string is the [[identity element]] of the [[concatenation]] operation. The set of all strings forms a [[free monoid]] with respect to ⋅ and ε.
* ε<sup>R</sup> = ε. Reversal of the empty string produces the empty string, so the empty string is a [[palindrome]].
* <math>\forall c \in s: P(c)</math>. Statements that are about all characters in a string are [[vacuous truth|vacuously true]].
* The empty string precedes any other string under [[lexicographical order]], because it is the shortest of all strings.<ref>[http://cs.fit.edu/~ryan/cse1002/lectures/lexicographic.pdf CSE1002 Lecture Notes – Lexicographic]</ref>
Line 20 ⟶ 21:
==Use in programming languages==
In most [[programming language]]s, strings are a [[data type]]. Strings are typically stored at distinct [[memory address]]es (locations). Thus, the same string (
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.
Line 29 ⟶ 30:
The empty string is usually represented similarly to other strings. In implementations with string terminating character ([[null-terminated string]]s or plain text lines), the empty string is indicated by the immediate use of this terminating character.
Different functions, methods, macros, or [[Programming idiom|idioms]] exist for checking if a string is empty in different languages.{{examples|date=July 2023}}
{| class="wikitable"
|-
Line 35 ⟶ 39:
|-
| <code>""</code>
| [[C (programming language)|C]], [[C Sharp (programming language)|C#]], [[C++]], [[Go (programming language)|Go]], [[Haskell (programming language)|Haskell]], [[Java (programming language)|Java]], [[JavaScript]], [[Julia (programming language)|Julia]], [[Lua (programming language)|Lua]], [[MUMPS|M]], [[Objective-C]] (as a C string), [[OCaml]], [[Perl]], [[PHP]], [[PowerShell]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Scala (programming language)|Scala]], [[Standard ML]], [[Swift (programming language)|Swift]], [[Tcl]], [[Visual Basic .NET]]
|-
| <code>''</code>
| [[APL (programming language)|APL]], [[Delphi (programming language)|Delphi]], [[JavaScript]], [[Lua (programming language)|Lua]], [[MATLAB]], [[Pascal (programming language)|Pascal]], [[Perl]], [[PHP]], [[PowerShell]], [[Python (programming language)|Python]], [[R (programming language)|R]], [[Ruby (programming language)|Ruby]], [[Smalltalk]], [[SQL]]
|-
| <code>character(0)</code>
Line 61 ⟶ 65:
| [[Perl]]
|-
| <code>str()</code><ref>Another way to make an empty string is multiplying a string by 0 or a negative integer.</ref>
| <code>str()</code>▼
| [[Python (programming language)|Python]]
|-
Line 81 ⟶ 85:
| <code><nowiki>[[]]</nowiki></code>
| [[Lua (programming language)|Lua]]
|-
<code>‘’</code>
<code>„”</code>
<code>‚‘</code>{{refn|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 {{code|"Hello, world„}} is valid. Guillemets are not supported. Note that the German-style low single quotation mark given here is {{Unichar|201A}}; the similar-looking character {{Unichar|2C}} does not function as a quotation mark. PowerShell's official documentation recommends using straight quotation marks.<ref>{{cite web |url=https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.5 |title=about_Quoting_Rules – PowerShell |work=Microsoft Learn |access-date=26 August 2025 |url-status=live |archive-url=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 |archive-date=2025-08-14 |quote=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.}}</ref>}}
|[[PowerShell]]
|}
===
{{Expand section|date=March 2010}}
The empty string is a syntactically valid representation of [[
Zero-filled memory area, interpreted as a [[null-terminated string]], is an empty string.
Empty lines of text show the empty string. This can occur from two consecutive [[End of line|EOLs]], as often occur in [[text file]]s
==See also==
* [[Empty set]]
* [[Null-terminated string]]
* [[Concatenation theory]]
* [[String literal]]
==References==
|