digitalmars.D.learn - string to byte array
- rickdiaz (6/6) Nov 04 2008 how do i convert a string of chars to byte array
- BCS (2/11) Nov 04 2008 yes
- BCS (3/12) Nov 04 2008 note: char[] is utf-8 so that might not do exactly what you expect if yo...
- james (2/18) Nov 04 2008 i wonder how you turn uint into ubyte array?, because above method wont ...
- Steven Schveighoffer (5/24) Nov 04 2008 uint i;
- james (2/33) Nov 04 2008 thanks alot
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
Nov 04 2008
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 advanceyes
Nov 04 2008
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 advancenote: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
Nov 04 2008
BCS Wrote:Reply to rickdiaz,i wonder how you turn uint into ubyte array?, because above method wont workhow do i convert a string of chars to byte array will this work: ubyte[] b; char[] s="test"; b = cast(ubyte[]) s; thx in advancenote: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
Nov 04 2008
"james" wroteBCS Wrote:uint i; auto ubarray = (cast(ubyte *)&i)[0..i.sizeof]; But be careful, you have to account for endianness. -SteveReply to rickdiaz,i wonder how you turn uint into ubyte array?, because above method wont workhow do i convert a string of chars to byte array will this work: ubyte[] b; char[] s="test"; b = cast(ubyte[]) s; thx in advancenote: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
Nov 04 2008
Steven Schveighoffer Wrote:"james" wrotethanks alotBCS Wrote:uint i; auto ubarray = (cast(ubyte *)&i)[0..i.sizeof]; But be careful, you have to account for endianness. -SteveReply to rickdiaz,i wonder how you turn uint into ubyte array?, because above method wont workhow do i convert a string of chars to byte array will this work: ubyte[] b; char[] s="test"; b = cast(ubyte[]) s; thx in advancenote: char[] is utf-8 so that might not do exactly what you expect if you are not careful about what you expect.
Nov 04 2008