print ubyte[] as (ascii) string
eugene
dee0xeed at gmail.com
Sun Jan 2 08:39:57 UTC 2022
On Friday, 31 December 2021 at 14:45:41 UTC, Steven Schveighoffer
wrote:
> Unless I'm misunderstanding:
>
> ```d
> import std.algorithm : until;
> writefln("got '%s' from '%s:%d'",
> (cast(char[])ioCtx.buf[]).until('\n'), client.addr,
> client.port);
> ```
```d
import std.stdio;
import std.string;
void main() {
ubyte[8] b = [0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x0A, 0x00, 0x00];
/* "hello\n\0\0" */
writefln("'%s, world'", cast(char[])b[].until('\n'));
}
```
```
@mono:~/2-coding/d-lang/misc$ dmd p1.d
p1.d(8): Error: no property `until` for type `ubyte[]`
```
```
@mono:~/2-coding/d-lang/misc$ dmd --version
DMD64 D Compiler v2.098.1
```
More information about the Digitalmars-d-learn
mailing list