I have a string in my database that represents an image. It looks like this:
0x89504E470D0A1A0A0000000D49484452000000F00000014008020000000D8A66040....
<truncated for brevity>
When I load it in from the database it comes in as a byte[]. How can I convert the string value to a byte array myself. (I am trying to remove the db for some testing code.)
It sounds like you’re asking how to convert a string with a particular encoding to a byte array.
If so, it depends on how the string is encoded. For example, if you have a base64 encoded string, then you could get a byte array using:
If the encoding is hexadecimal (as it appears to be in your example) there’s nothing built into the BCL, but you could use LINQ (just remove the
0xat the head of the string first):