String Literals

Part of TutorialIntermediate

Description

Shows how different types of string literals work.

Example

/* "Backquote" WYSIWYG strings */

const char[] a1 = `\`;
const char[] b1 = `\\`;
const char[] c1 = `\"`;


/* r"" WYSIWYG strings */

const char[] a2 = r"\";
const char[] b2 = r"\\";
const char[] c2 = r"\" `"`; 
/* The r"" strings can't contain a ", so I used concatenation. */


/* "Regular strings */

const char[] a3 = "\\";
const char[] b3 = "\\\\";
const char[] c3 = "\\\"";


void main()
{
    printf("Test that the strings mean what I think they mean.\n");

    assert(a1 == a2);
    assert(a1 == a3);

    assert(b1 == b2);
    assert(b1 == b3);

    assert(c1 == c2);
    assert(c1 == c3);

    printf("Tests passed!\n");
}

Source

Link http://www.dsource.org/tutorials/index.php?show_example=98
Posted by jcc7
Date/Time Sat Jun 19, 2004 4:30 pm