Due to an odd conjunction of stars (trust me, thats a better reason than the real one), I need to store text data in a SQLServer Image column
I'm looking for a cleaner method to convert strings to byte[] and vice versa. So far the only implementation I have been able to make work has been to do an iteration of the array and convert one character at a time in either direction
I've looked into Streams and Textwriters but none of them seem to be quite what I need. Can anyone suggest a cleaner method of doing a conversion than the rather clunky
for(int i=0; i< myChars.Length; i++) { myBytes[i] = Convert.ToByte(myChars[i]);
?
> Due to an odd conjunction of stars (trust me, thats a better reason
> than the real one), I need to store text data in a SQLServer Image
[quoted text clipped - 9 lines]
> conversion than the rather clunky: for(int i=0; i< myChars.Length;
> i++) { myBytes[i] = Convert.ToByte(myChars[i]); }
That's not just clunky - it's broken. As soon as you've got a character
with a Unicode value greater than 255, you'll get an exception.
Fortunately, the Encoding class is provided to do exactly what you
want. Just select the encoding you want and call GetBytes.
See http://www.pobox.com/~skeet/csharp/unicode.html for more
information.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too