Converting from C const(dchar*) to dstring
Danyal Zia via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 24 12:09:46 PDT 2014
On Tuesday, 24 June 2014 at 18:34:31 UTC, Chris Cain wrote:
> You can do what he said, but you'll have to write your own
> strlen function:
>
> something like:
>
> size_t strlen(in dchar* s) pure @system nothrow
> {
> size_t pos = 0;
> dchar term = '\0';
> while(s[pos] != term)
> ++pos;
> return pos;
> }
> const(dchar)* ds = "hello\0";
> dstring text = ds[0..strlen(ds)].idup;
> writeln(text);
>
> works
It works indeed, thanks a lot! Any chance of making it into std
phobos?
More information about the Digitalmars-d-learn
mailing list