Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Empty string

From Wikipedia, the free encyclopedia
"""" redirects here. For the printed character, seeQuotation mark.
Unique string of length zero
icon
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.

Formal theory

[edit]

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".

Use in programming languages

[edit]

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]

λ representationProgramming 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++
""sC++ (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
“”

‘’„”‚‘[7]

PowerShell
.byte 0

.ascii "".asciz ""

A64

Representations of the empty string

[edit]
[icon]
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.

See also

[edit]

References

[edit]
  1. ^Corcoran, John; Frank, William; Maloney, Michael (1974). "String theory".Journal of Symbolic Logic.39 (4):625–637.doi:10.2307/2272846.JSTOR 2272846.S2CID 2168826.
  2. ^"CSE1002 Lecture Notes – Lexicographic"(PDF). Archived fromthe original(PDF) on 2009-12-29. Retrieved2010-03-27.
  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.
  4. ^Another way to make an empty string is multiplying a string by 0 or a negative integer.
  5. ^"String in std::string - Rust".doc.rust-lang.org. Retrieved2022-11-30.
  6. ^"about_Quoting_Rules – PowerShell".Microsoft Learn.Archived from the original on 2025-08-14. Retrieved26 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.
  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 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]
Retrieved from "https://en.wikipedia.org/w/index.php?title=Empty_string&oldid=1333190339"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp