Character and string Literals
Explore the use of character and string literals in D programming. Understand how to specify characters using escape sequences, Unicode codes, and various string literal forms like WYSIWYG and delimited strings. Learn how literals are handled at compile time to optimize your code.
We'll cover the following...
Character literals #
Character literals are specified within single quotes as in ‘a’, ‘\n’, ‘\x21’, etc.
As the character itself #
The character may be typed directly using the keyboard or copied from a separate text: ‘a’, ‘ş’.
As the character specifier #
The character literal may be specified using a backslash
character followed by a special character. For example, the backslash character itself can be specified by \\. The following character specifiers are accepted:
As the extended ASCII character code #
Character literals can also be specified by their codes. The codes can be specified either in the hexadecimal system or in the octal system. When using the hexadecimal system, the literal must start with \x and must use two digits for the code. Additionally, when using the octal system the literal must start with \ and have up to three digits. For ...