print ubyte[] as (ascii) string

eugene dee0xeed at gmail.com
Sun Jan 2 09:15:32 UTC 2022


On Sunday, 2 January 2022 at 08:39:57 UTC, eugene wrote:
> ```d
> import std.stdio;
> import std.string;
> ```

oops...

```d
import std.stdio;
import std.string;
import std.algorithm : until;

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'));
}

```

```
p1.d(9): Error: cannot cast expression `until(b[], '\x0a', 
Flag.yes)` of type `Until!("a == b", ubyte[], char)` to `char[]`

```



More information about the Digitalmars-d-learn mailing list