toChars buffer access?

Salih Dincer salihdb at hotmail.com
Fri Jun 10 05:07:44 UTC 2022


On Friday, 10 June 2022 at 01:49:25 UTC, Steven Schveighoffer 
wrote:
> On 6/9/22 8:18 PM, Salih Dincer wrote:
>>    auto test = result.to!char[];
>
> I'm not sure if I got all your code, but just to note, the 
> operator precedence here means it's `(result.to!char)[]`
> [...]

It's okay, the subject is clearer for me now.

But I wish I could change each character to hexString without 
dealing with conversions; I see below is the type of 
integer(uint) that toChars wants:

```d
void main() {
   import std.algorithm, std.range;
   import std.conv, std.stdio;

   string str = "Hello World!";

   /* 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("-")
   );

   writeln;

   str.each!((i, uint c) {
     c.to!string(16)
      .writeln(": ", i);
     }
   );//*/
} /* Print Out:
48-65-6C-6C-6F-20-57-6F-72-6C-64-21-
48: 0
65: 1
6C: 2
6C: 3
6F: 4
20: 5
57: 6
6F: 7
72: 8
6C: 9
64: 10
21: 11

//*/
```

SDB at 79


More information about the Digitalmars-d mailing list