Thread overview |
---|
November 05, 2008 string to byte array | ||||
---|---|---|---|---|
| ||||
how do i convert a string of chars to byte array will this work: ubyte[] b; char[] s="test"; b = cast(ubyte[]) s; thx in advance |
November 05, 2008 Re: string to byte array | ||||
---|---|---|---|---|
| ||||
Posted in reply to rickdiaz | Reply to rickdiaz,
> how do i convert a string of chars to byte array
>
> will this work:
>
> ubyte[] b;
> char[] s="test";
> b = cast(ubyte[]) s;
> thx in advance
>
yes
|
November 05, 2008 Re: string to byte array | ||||
---|---|---|---|---|
| ||||
Posted in reply to rickdiaz | Reply to rickdiaz,
> how do i convert a string of chars to byte array
>
> will this work:
>
> ubyte[] b;
> char[] s="test";
> b = cast(ubyte[]) s;
> thx in advance
>
note: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
|
November 05, 2008 Re: string to byte array | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS Wrote:
> Reply to rickdiaz,
>
> > how do i convert a string of chars to byte array
> >
> > will this work:
> >
> > ubyte[] b;
> > char[] s="test";
> > b = cast(ubyte[]) s;
> > thx in advance
> >
>
> note: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
>
>
i wonder how you turn uint into ubyte array?, because above method wont work
|
November 05, 2008 Re: string to byte array | ||||
---|---|---|---|---|
| ||||
Posted in reply to james | "james" wrote
> BCS Wrote:
>
>> Reply to rickdiaz,
>>
>> > how do i convert a string of chars to byte array
>> >
>> > will this work:
>> >
>> > ubyte[] b;
>> > char[] s="test";
>> > b = cast(ubyte[]) s;
>> > thx in advance
>> >
>>
>> note: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
>>
>>
>
> i wonder how you turn uint into ubyte array?, because above method wont work
uint i;
auto ubarray = (cast(ubyte *)&i)[0..i.sizeof];
But be careful, you have to account for endianness.
-Steve
|
November 05, 2008 Re: string to byte array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | Steven Schveighoffer Wrote:
> "james" wrote
> > BCS Wrote:
> >
> >> Reply to rickdiaz,
> >>
> >> > how do i convert a string of chars to byte array
> >> >
> >> > will this work:
> >> >
> >> > ubyte[] b;
> >> > char[] s="test";
> >> > b = cast(ubyte[]) s;
> >> > thx in advance
> >> >
> >>
> >> note: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
> >>
> >>
> >
> > i wonder how you turn uint into ubyte array?, because above method wont work
>
> uint i;
> auto ubarray = (cast(ubyte *)&i)[0..i.sizeof];
>
> But be careful, you have to account for endianness.
>
> -Steve
>
>
thanks alot
|
Copyright © 1999-2021 by the D Language Foundation