Jump to page: 1 2
Thread overview
Does D has C#'s string.Empty?
Sep 25, 2014
AsmMan
Sep 25, 2014
SlomoTheBrave
Sep 26, 2014
AsmMan
Sep 26, 2014
ketmar
Sep 26, 2014
AsmMan
Sep 26, 2014
ketmar
Sep 26, 2014
ketmar
Sep 26, 2014
Chris Cain
Sep 26, 2014
H. S. Teoh
Sep 26, 2014
AsmMan
Sep 25, 2014
Daniel Kozak
Sep 25, 2014
SlomoTheBrave
September 25, 2014
Does D has C#'s string.Empty?
September 25, 2014
On Thursday, 25 September 2014 at 05:29:37 UTC, AsmMan wrote:
> Does D has C#'s string.Empty?

string.init ?

----
    string a;
    a = string.init;
    assert( a == "");
----

does the job for the type string at least.

September 25, 2014
V Thu, 25 Sep 2014 05:29:36 +0000
AsmMan via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
napsáno:

> Does D has C#'s string.Empty?

string.init

September 25, 2014
On Thursday, 25 September 2014 at 06:41:55 UTC, Daniel Kozak via Digitalmars-d-learn wrote:
> V Thu, 25 Sep 2014 05:29:36 +0000
> AsmMan via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
> napsáno:
>
>> Does D has C#'s string.Empty?
>
> string.init

first ^^

September 25, 2014
On 9/25/14 2:41 AM, SlomoTheBrave wrote:
> On Thursday, 25 September 2014 at 05:29:37 UTC, AsmMan wrote:
>> Does D has C#'s string.Empty?
>
> string.init ?
>
> ----
>      string a;
>      a = string.init;
>      assert( a == "");
> ----
>
> does the job for the type string at least.
>
null also works. In fact, in the above, a is already string.init or null before assigning (D always initializes variables unless asked not to).

a = null; // same as a = string.init;

-Steve
September 26, 2014
On Thursday, 25 September 2014 at 06:41:03 UTC, SlomoTheBrave wrote:
> On Thursday, 25 September 2014 at 05:29:37 UTC, AsmMan wrote:
>> Does D has C#'s string.Empty?
>
> string.init ?
>
> ----
>     string a;
>     a = string.init;
>     assert( a == "");
> ----
>
> does the job for the type string at least.

Thanks.:)
September 26, 2014
On Thursday, 25 September 2014 at 12:43:57 UTC, Steven
Schveighoffer wrote:
> On 9/25/14 2:41 AM, SlomoTheBrave wrote:
>> On Thursday, 25 September 2014 at 05:29:37 UTC, AsmMan wrote:
>>> Does D has C#'s string.Empty?
>>
>> string.init ?
>>
>> ----
>>     string a;
>>     a = string.init;
>>     assert( a == "");
>> ----
>>
>> does the job for the type string at least.
>>
> null also works. In fact, in the above, a is already string.init or null before assigning (D always initializes variables unless asked not to).
>
> a = null; // same as a = string.init;
>
> -Steve

It made me a bit confusing. How is the implementation of string
comparasion in D? (if someone could point to actual code used in
these comparasion would be really great otherwise I'll check out
assembly output, maybe) in no language I know of (including C#)
"" == null is true
September 26, 2014
On Fri, 26 Sep 2014 00:24:27 +0000
AsmMan via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> It made me a bit confusing. How is the implementation of string comparasion in D?
"" has length of 0. null has length of 0. two strings without content are essentialy the same.


September 26, 2014
On Friday, 26 September 2014 at 00:53:24 UTC, ketmar via Digitalmars-d-learn wrote:
> On Fri, 26 Sep 2014 00:24:27 +0000
> AsmMan via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
> wrote:
>
>> It made me a bit confusing. How is the implementation of string
>> comparasion in D?
> "" has length of 0. null has length of 0. two strings without content
> are essentialy the same.

but null has length? what's null in D?
September 26, 2014
On Fri, 26 Sep 2014 01:08:59 +0000
AsmMan via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
wrote:

> but null has length? what's null in D?
no, it's dynamic array that have `.length`. compiler magic. assigning `null` to dynamic array variable does some magic under the hood.

dynamic array is actually this: `struct { size_t len; void* ptr};`. when you assign `null` to dynamic array variable, compiler generates code to clear both `len` and `ptr`. think about dynarray var as kind of 'fat pointer', which compiler knows how to operate.


« First   ‹ Prev
1 2