How to place char* of stringZ to ubyte[]?

denizzzka 4denizzz at gmail.com
Mon Oct 29 11:06:31 PDT 2012


On Monday, 29 October 2012 at 17:51:56 UTC, bearophile wrote:
> denizzzka:
>
>> immutable ubyte[] valueBin = cast(immutable(ubyte[])) 
>> toStringz(s); // s is string type
>>
>> Error: e2ir: cannot cast toStringz(s) of type immutable(char)* 
>> to type immutable(ubyte[])
>
> One way to do it:
>
>
> import std.stdio;
> void main() {
>     string s = "hello";
>     auto valueBin = cast(immutable ubyte[])s.dup;
>     writeln(valueBin);
> }
>
>
> But what are you trying to do?

I am trying to send to remote host utf8 text with zero byte at 
end (required by protocol)

But sending function accepts only ubyte[]


More information about the Digitalmars-d-learn mailing list