Enum member std.conv.hexString
Converts a hex literal to a string at compile time.
enum hexString(string hexData) = mixin(hexToString(hexData));
enum hexString(wstring hexData) = mixin(hexToString(hexData));
enum hexString(dstring hexData) = mixin(hexToString(hexData));
Takes a string made of hexadecimal digits and returns the matching string by converting each pair of digits to a character. The input string can also include white characters, which can be used to keep the literal string readable in the source code.
The function is intended to replace the hexadecimal literal strings
starting with 'x'
, which could be removed to simplify the core language.
Parameters
Name | Description |
---|---|
hexData | string to be converted. |
Returns
a string
, a wstring
or a dstring
, according to the type of hexData.
See Also
Use std
for run time conversions.
Note, these functions are not drop-in replacements and have different
input requirements.
This template inherits its data syntax from builtin
hex strings.
See std
for its own respective requirements.
Example
// conversion at compile time
auto string1 = hexString!"304A314B";
writeln(string1); // "0J1K"
auto string2 = hexString!"304A314B"w;
writeln(string2); // "0J1K"w
auto string3 = hexString!"304A314B"d;
writeln(string3); // "0J1K"d
Authors
Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara