phobos icon indicating copy to clipboard operation
phobos copied to clipboard

std.format could support %{x,X} for ubyte[]

Open dlangBugzillaToGithub opened this issue 4 years ago • 1 comments

pro.mathias.lang (@Geod24) reported this on 2021-04-18T18:22:47Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=21843

CC List

  • bugzilla (@WalterBright)

Description

```
import std;

void main ()
{
    ubyte[] data = [42, 69, 250];
    writefln("%X", data);
}
```

This currently throws an Exception. I think it could print `2A45FA`. This would be very handy to save on space when printing large ubyte arrays. This is an enhancement request, as there is nothing wrong with the current behavior.

dlangBugzillaToGithub avatar Apr 18 '21 18:04 dlangBugzillaToGithub

bugzilla (@WalterBright) commented on 2021-04-19T15:52:25Z

You can use

writefln!"%(%02X%)"(data);

to get the desired result. (But %X might be useful as a shortcut, so leaving this open.)

dlangBugzillaToGithub avatar Apr 19 '21 15:04 dlangBugzillaToGithub