Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Empty string
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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 (e.g., the empty string) may 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 points to no string at all, not even the empty string. <!---A null reference is likely to cause an error if one tries to perform any operation on it, but an empty string is less likely to do so.---> 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 (logic)|false]], the [[ASCII]] character [[null character|NUL]], or other such values. 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" |- ! Ξ» representation ! Programming languages |- | <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> | [[R (programming language)|R]]{{Refn|There are two ways to create "empty strings" in R; the other is listed here as <code>""</code>. <code>character(0)</code> creates empty character vectors, which will output 0 when counted.}} |- | <code>{'\0'}</code> | [[C (programming language)|C]], [[C++]], [[Objective-C]] (as a C string) |- | <code>std::string()</code> | [[C++]] |- | <code>""s</code> | [[C++]] (since the [[C++14|2014 standard]]) |- | <code>@""</code> | [[Objective-C]] (as a constant <code>NSString</code> object) |- | <code>[NSString string]</code> | [[Objective-C]] (as a new <code>NSString</code> object) |- | <code>q(), qq()</code> | [[Perl]] |- | <code>str()</code><ref>Another way to make an empty string is multiplying a string by 0 or a negative integer.</ref> | [[Python (programming language)|Python]] |- | <code>%{}</code><br /><code>%()</code> | [[Ruby (programming language)|Ruby]] |- | <code>String::new()</code><ref>{{Cite web |title=String in std::string - Rust |url=https://doc.rust-lang.org/std/string/struct.String.html#method.new |access-date=2022-11-30 |website=doc.rust-lang.org}}</ref> | [[Rust (programming language)|Rust]] |- | <code>string.Empty</code> | [[C Sharp (programming language)|C#]], [[VB.NET|Visual Basic .NET]] |- | <code>String.make 0 '-'</code> | [[OCaml]] |- | <code>{}</code> | [[Tcl]] |- | <code><nowiki>[[]]</nowiki></code> | [[Lua (programming language)|Lua]] |- |<code>ββ</code> <code>ββ</code> |[[PowerShell]] |} === Representations of the empty string === {{Expand section|date=March 2010}} The empty string is a syntactically valid representation of [[zero]] in [[positional notation]] (in any base), which does not contain [[leading zero]]s. 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]] '''0''' instead. 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. This is sometimes used in [[text processing]] to separate [[paragraph]]s, e.g. in [[MediaWiki]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)