toChars buffer access?

Steven Schveighoffer schveiguy at gmail.com
Fri Jun 10 14:49:51 UTC 2022


On 6/10/22 1:07 AM, Salih Dincer wrote:
>    /* I'd like it to be as simple as a
>     * comment line, but it's not working.
>     */
>    //str.toChars!(16, string).writeln;/*
>    str.each!(c =>
>      c.to!uint
>       .toChars!(16, char, LetterCase.upper)
>       .write("-")
>    );

Ugh, it's not as easy as I thought but...

```d
   import std.utf;
   // option 1 (if you want a range that's usable elsewhere)
   str.map!(c => uint(c).toChars!(16, char, LetterCase.upper))
       .joiner("-".byCodeUnit) // byCodeUnit needed because of autodecoding
       .writeln;

   // option 2 (if the point is just to print)
   writefln("%-(%02X-%)", str);
```

-Steve


More information about the Digitalmars-d mailing list