On Wed, Aug 14, 2019 at 03:11:44PM +, berni via Digitalmars-d-learn wrote:
[...]
> 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 expr
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;
On Wednesday, 14 August 2019 at 15:11:44 UTC, berni wrote:
The reason is, that this expression creates a string and not a
ubyte[]...
it should be ok to just cast it in this case.
On Saturday, 11 November 2017 at 15:48:59 UTC, Mike Parker wrote:
auto s = "hello";
auto bytes = s.representation;
https://dlang.org/phobos/std_string.html#.representation
Thank you for the replay.
Now I know.
aki
On Saturday, 11 November 2017 at 15:48:59 UTC, Mike Parker wrote:
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
[...]
I don't know about the error you're seeing, but the generic way
to get an array of the underlying data type of a string is via
std.string.representation.
import
On Saturday, 11 November 2017 at 15:48:59 UTC, Mike Parker wrote:
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
auto bytes = cast(immutable(ubyte)[])s;
Of course, if you need a mutable array you should dup:
auto bytes = cast(ubyte[])s.dup;
Not only "should" but he "must" otherwise
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
Hello,
This will be trivial question but I cannot figure out
what's wrong. I want to convert string to an array of ubyte.
import std.conv;
void main() {
auto s = "hello";
ubyte[] b = to!(ubyte[])(s);
}
It compiles but ca
On Saturday, 11 November 2017 at 15:38:18 UTC, aki wrote:
Hello,
This will be trivial question but I cannot figure out
what's wrong. I want to convert string to an array of ubyte.
import std.conv;
void main() {
auto s = "hello";
ubyte[] b = to!(ubyte[])(s);
}
It compiles but ca
Hello,
This will be trivial question but I cannot figure out
what's wrong. I want to convert string to an array of ubyte.
import std.conv;
void main() {
auto s = "hello";
ubyte[] b = to!(ubyte[])(s);
}
It compiles but cause run time error:
std.conv.ConvException@C:\APP\D\dmd2\w