Best way to read/write Chinese (GBK/GB18030) files?

0xEAB desisma at heidel.beer
Sun Mar 12 20:03:23 UTC 2023


On Sunday, 12 March 2023 at 00:54:53 UTC, zjh wrote:
> On Saturday, 11 March 2023 at 19:56:09 UTC, 0xEAB wrote:
>
>> If you desire to use other encodings, how about using ubyte + 
>> ubyte[]?
>
>
> There is no example.

To read binary data from a file and dump it into another, you do:

```d
import std.file : read, write;

void[] data = read("infile.txt");
write("outfile.txt", data);
```

To write binary data to a file:

```d
import std.file : write;

ubyte[] data = [0xA0, 0x0A, 0x30, 0x01, 0xFF, 0x00, 0xFE];
write("myfile.txt", data);
```

`data` could contain GBK encoded text, for example. (Just don’t 
use `"Unicode literals"`.)



More information about the Digitalmars-d-learn mailing list