Convert a hex string into a ubyte[] or OutBuffer

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jan 7 15:05:50 PST 2016


On Thursday, 7 January 2016 at 21:00:06 UTC, zabruk70 wrote:
> Hello.
> In modern phobos ver 2.069.1 exists template hexString
>
> https://dlang.org/phobos/std_conv.html#.hexString
>
> to convert hex string to bytes.
> It works in compile time only.
> But what if i need it in run time?
>
> Is the answer in this topic still best way?
> Or now we have some function/template in phobos?
>
> Thanks.

The original PR that proposed a template to translate x strings 
as a template contained the Run-Time version too. Archeology...

https://github.com/D-Programming-Language/phobos/pull/3058/files#diff-ebd0b0e1b0171283328bda4a570616b9R5570

But otherwise take the solution by anonymous. The thing with 
hexString is just that it handles ascii whites so it can be used 
to process hex dumps directly using the import expression:

---
static ubyte[] dumpToArray = hexString!import(dump.txt);
---

Which was maybe a "faddishness" from Walter (no offense here, but 
it's clear that D is a bit over the top as for the profusion of 
string literals: x"", r"", ``, q{}, ""w, ""d, delimited, here 
doc, ...).

:)




More information about the Digitalmars-d-learn mailing list