Formatting floats and ints

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Mar 15 11:52:28 PDT 2015


On Sunday, 15 March 2015 at 17:11:07 UTC, Darts wrote:
> Thanks! That works perfectly! ;) I'll remember they're called 
> Format Strings now.
>
> Tangentially related follow up: if I want to cast a string to a 
> dstring... what are the rules for that? I'm getting an 
> "object.Error@(0): array cast misalignment" message when my 
> program crashes tring to convert a string to a dstring...

Casting in this case means reinterpreting the bytes of the 
`string` as if it were a `dstring`. For this to work, the string 
would have to start at an address and have and address divisible 
by 4, which it evidently doesn't.

Anyway, what you want is:

     import std.conv : to;
     string a = "Hello, world!";
     dstring b = a.to!dstring;


More information about the Digitalmars-d-learn mailing list