String Theory Questions
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 13 17:44:19 PDT 2014
On Sun, 14 Sep 2014 00:34:54 +0000
WhatMeWorry via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:
> So is one form (Empty strings versus null strings) considered
> better than the other? Or does it depend on the context?
one is better than another in the sense that blue is better than green
(or vice versa). ;-)
don't count on that trailing zero, and don't count on empty string
being null or points to somewhere. `.length` is all that matters.
> Also as an aside (and I'm not trying to be flippant here), aren't
> all strings literals? I mean, can someone give me an example of
> a string non-literal?
string foo () {
import std.conv;
string s;
foreach (i; 0..10) s ~= to!string(i);
return s;
}
this function returns string, but that string is in no way built
from literal.
note that it's string *contents* are immutable, not the whole string
structure. there is a difference between `immutable(char[])` and
`immutable(char)[]`. that is why you can use `~=` on strings.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140914/fb643656/attachment.sig>
More information about the Digitalmars-d-learn
mailing list