Array slicing

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Dec 14 10:10:31 PST 2006


Heinz wrote:
> Hi, i'm trying to slice an array of chars and print it to the screen but it
> doesn't seems to work, here's the code:
> 
> /////////////////////////////////////
> import std.string;
> 
> alias char[] string;
> 
> int main(char[][] args)
> {
>     printf("hello world\n");
> 	string hw = "Hello_World";
> 	printf(cast(char*)hw[0 .. 5]);
>     return 0;
> }
> 
> /////////////////////////////////////
> 
> What could be wrong? it just prints to the output "Hello_World".

printf expects a zero terminated string. Try:

printf(toStringz(hw[0 .. 5]));

or why not use writef instead.

/Oskar


More information about the Digitalmars-d-learn mailing list