...
/Characters: D's Unicode Problems and Support
Characters: D's Unicode Problems and Support
In this lesson, we explore problems with reading D's Unicode characters and D's Unicode support.
We'll cover the following...
Problems with reading characters #
The flexibility and power of D’s Unicode characters may cause unexpected results when reading characters from an input stream. This happens due to the multiple meanings of the term character. Before expanding on this further, let’s look at a program that exhibits this problem:
import std.stdio;void main() {char letter;write("Please enter a letter: ");readf(" %s", &letter);writeln("The letter that has been read: ", letter);}
Enter the input below
If you test this program in an environment that does not use Unicode, you may see that all the characters are read and displayed as ASCII.
On the other hand, if you start the same program in an environment with Unicode support (e.g., a Linux terminal), you may see that the character displayed on the output is not the same character that has been entered. To see this, let’s enter a non-ASCII character in a terminal that uses the UTF-8 encoding (like most Linux terminals):
Please enter a letter: ğ
The letter that has been read: ← no letter on the output
...