How to convert hex string to string or ubytes? Thanks.

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Feb 5 06:12:22 UTC 2018


On Mon, Feb 05, 2018 at 05:48:00AM +0000, FrankLike via Digitalmars-d-learn wrote:
> Now,I can get the string from hex string in compile time,but how to
> get it in run time?
> 
> How to get it in run time?
[...]

Oh wait, I think I misunderstood your original question. Perhaps this is
closer to what you want:

	import std.algorithm;
	import std.array;
	import std.conv;
	import std.range;

	auto input = "48656c6c6f20776f726c6421";
	auto str = input.chunks(2)
	                .map!(digits => cast(char) digits.to!ubyte(16))
			.array;
	assert(str == "Hello world!");


T

-- 
Study gravitation, it's a field with a lot of potential.


More information about the Digitalmars-d-learn mailing list