mutable string

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 10 14:38:26 PDT 2016


On 07/10/2016 11:26 PM, Adam Sansier wrote:
> For example, I'm trying to compare a wchar buffer with a wstring using
> slices:
>
> x[0..$] == y[0..$]
>
> It fails. I think because x has length 1024. If do
>
> x[0..y.length] == str[0..y.length]
>
> it fails, also because y has length 1024(since it was generated from a
> buffer and the length wasn't set correctly).

So you fill the buffer with a call to some Windows function. The Windows 
function either returns the amount of data it wrote, and/or it 
zero-terminates the string which it writes.

If it returns the length, you use that when slicing the buffer. Then you 
can compare.

If it zero-terminates, you search for zero in the buffer and count along 
to determine the length. I wanted to say that there's a function for 
this in phobos, but fromStringz [1] seems to be for char arrays only.


[1] https://dlang.org/phobos/std_string.html#.fromStringz


More information about the Digitalmars-d-learn mailing list