UTF-8 char and write(f)ln
Vindex9
tech.vindex at gmail.com
Tue Mar 4 08:09:30 UTC 2025
Program:
```d
import std.stdio;
void main() {
string s = "ταυ";
foreach(i, elem; s) {
writefln("%s %s '%s'", i, cast(int)elem, elem);
writefln("%s", elem);
}
}
```
Output:
```
0 207 '�'
1 132 '�'
τ
2 206 '�'
3 177 '�'
α
4 207 '�'
5 133 '�'
υ
```
How does the second writefln know about the context and can
adequately output a character on every other iteration?
However, if you do it this way (see below), the output is very
strange with arbitrary line breaks.
```d
foreach(i, elem; s) {
writefln("'%s', %s", elem, elem);
}
```
Output:
```
'�',
�'�', �
'�',
�'�', �
'�',
�'�', �
```
More information about the Digitalmars-d-learn
mailing list