string to ubyte[]
berni
someone at somewhere.com
Wed Aug 14 15:11:44 UTC 2019
I've got a function which takes two strings and should return
them as a ubyte[] with additional zero bytes in between and
around. This works:
> ubyte[] convert_string_pair(string first, string second)
> {
> auto b = new ubyte[](0);
> b ~= 0x00 ~ first ~ 0x00 ~ second ~ 0x00;
> return b;
> }
But I think it would be more elegant to do it in a single return
statement, but unfortunately this does not work:
> ubyte[] convert_string_pair(string first, string second)
> {
> return 0x00 ~ first ~ 0x00 ~ second ~ 0x00;
> }
The reason is, that this expression creates a string and not a
ubyte[]...
More information about the Digitalmars-d-learn
mailing list