Converting from C const(dchar*) to dstring

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 24 10:59:41 PDT 2014


On Tue, 24 Jun 2014 13:37:41 -0400, Danyal Zia <catofdanyal at yahoo.com>  
wrote:

> Hi, I like to print the strings from a C function that returns  
> const(dchar*), but I can't make the conversion to dstring. I can convert  
> vice versa by:
>
> dstring text = "Hello";
> const(dchar)* str = toUTFz!(const(dchar)*)(text);
> // passing it to C function prints Hello
>
> However, I don't have the idea how can I go the other way. I tried  
> several methods such as using to!dstring, toUTF32 etc which compiles  
> successfully however printing them gives address of them instead of text.

const(dchar *)x = ...;

// assuming 0 terminated
dstring text = x[0..x.strlen].idup;

-Steve


More information about the Digitalmars-d-learn mailing list