Note: This website is archived. For up-to-date information about D projects and development, please visit

Printing a Slice from a String

Part of CommonErrorsCategory


Shows the trick for printing a slice from a character string.


int main( char [] [] args ) 
    char[] pr = "Hello Jon Thoroddsen !"[0..5];

    printf(pr ~ \0); 
    /* If the \0 isn't appended, you might get more characters than you expected. */

    return 1;


Based on code in post D:19840 by Jon Thoroddsen.