Characters: Types and Literals

In this lesson, we see character types and literals. Furthermore, we will explore control characters and the use of single quotes and backslash in D.

The character types of D #

There are three D types to represent characters. These characters correspond to the three Unicode encodings mentioned previously: UTF-32, UTF-16, and UTF-8. Copying from the fundamental types lesson:

Compared to some other programming languages, characters in D may consist of a different number of bytes. For example, because ‘Ğ’ must be represented by at least 2 bytes in Unicode, it doesn’t fit in a variable of type char. On the other hand, because dchar consists of 4 bytes, it can hold any Unicode character.

Character literals #

Literals are constant character values that are written ...