Timeline for C# Byte[] Byte array to Unicode string
Current License: CC BY-SA 3.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jan 5, 2022 at 12:55 | comment | added | xanatos | @variable It all depends on how the string was encoded in the byte array. There are many ways to encode it, and for each way to encode there is a single way to decode. | |
Jan 5, 2022 at 11:15 | comment | added | variable |
If I use this then it returns diamonds in the result. Where as this works: Convert.ToBase64String - why is that?
|
|
May 16, 2018 at 10:19 | comment | added | Dmitry Gusarov | @SNag, avoid usages of ASCII, this is only for the last resort, when you are absolutely known what are you doing and why. 1) By default first thing to play with must be UTF8 encoding 2) If for some reason you are dealing with an old non-unicode data you can try Encoding.Default 3) Only as a fallback if you explicitly going to stick with 0-127 byte values range and Latin chars only you can try ASCII (7bit that fits into 8bit) In the author's case it is clear that data is UTF16 encoded and this is why Encoding.Unicode is correct here. This is mostly used by inmemory blobs. | |
Jan 7, 2016 at 17:43 | comment | added | SNag |
I had to use Encoding.ASCII.GetString instead of Encoding.Unicode.GetString in my case to get it to work.
|
|
Nov 22, 2013 at 10:53 | comment | added | sabotero |
@xanatos, @alex technically var in JavaScript is not a type like you're saying. var in JavaScript is a keyword meaning I'm wanting to declare a variable here which type is inferred later.
|
|
Apr 9, 2013 at 13:21 | comment | added | xanatos |
@Alex This is C#, not Javascript. var isn't a type. It's an abbreviation for "the type of the right-hand expression" (so string ) (see for example stackoverflow.com/questions/41479/use-of-var-keyword-in-c-sharp )
|
|
Apr 9, 2013 at 11:30 | comment | added | Alex |
@xanatos why do you use var type?
|
|
Oct 26, 2011 at 15:46 | history | edited | xanatos | CC BY-SA 3.0 |
added 66 characters in body
|
Feb 20, 2011 at 11:18 | vote | accept | Hooch | ||
Feb 20, 2011 at 11:06 | history | edited | xanatos | CC BY-SA 2.5 |
added 56 characters in body; added 4 characters in body
|
Feb 20, 2011 at 10:08 | history | answered | xanatos | CC BY-SA 2.5 |