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

Printing a Slice from a String

Part of CommonErrorsCategory

Description

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

Example

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;
}

Source

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