| View previous topic :: View next topic |
| Author |
Message |
blackmorpheus Expert Cheater
Reputation: 0
Joined: 05 Apr 2008 Posts: 159
|
Posted: Sun Sep 20, 2009 1:12 pm Post subject: [C#]String Encoding problem |
|
|
Hi, i'm reading a string from a file.
The String looks like this: 04 00 0a bd ff de
i need to convert it to a byte array like this:
{0x04, 0x00, 0x0A, 0xBD, 0xFF, 0xDE}
Can't really figure out how to do it.
|
|
| Back to top |
|
 |
ElJEffro Grandmaster Cheater Supreme
Reputation: 0
Joined: 15 Apr 2007 Posts: 1881 Location: La Tierra
|
Posted: Mon Sep 21, 2009 8:45 pm Post subject: |
|
|
Simple.
| Code: |
string bytestring = "30 54 43 43 99";
string[] stripped = bytestring.Split(' ');
List<byte> decodedbytes;
byte bb;
foreach ( string s in stripped )
{
if (byte.TryParse(s, System.Globalization.NumberStyles.AllowHexSpecifier, null, out bb)
decodedbytes.Add(bb);
}
byte[] desiredbytes= decodedbytes.ToArray(); |
|
|
| Back to top |
|
 |
|