Empty string vs null
mark
mark at qtrac.eu
Tue Feb 4 07:44:08 UTC 2020
Just found this post by Mark Parker that explains:
https://forum.dlang.org/post/gvveit$10i5$1@digitalmars.com
// test.d
import std.stdio;
import std.string;
void main()
{
report(null, "null");
report("");
report("x");
}
void report(const string x, const string name=null) {
writeln("\nx = \"", name is null ? x : name, "\"");
writeln("null = ", x is null);
writeln("\"\" = ", x == "");
writeln("empty = ", x.empty);
}
Output:
x = "null"
null = true
"" = true
empty = true
x = ""
null = false
"" = true
empty = true
x = "x"
null = false
"" = false
empty = false
More information about the Digitalmars-d-learn
mailing list