c# - Null and Space char decoding in ASCII 8-bit encoded file -


I have an ASCII-extended txt file and I have to convert it to a byte array. The problem is that the faucet room and location are decoded with the same 0x20 value. How can I discriminate between these cases? The file is created by serial logger hardware that saves the bytes given on serial port in ASCIII extended txt file. Here is the console app code:

  class program {static zero main (string [] args) {Encoding enc = Encoding.GetEncoding (1252); Byte [] bytere; String filePath = "C: \\ log.txt"; If (file.exist (file path)) {StreamReader sr = new streamreader (file path, enc); String fileString = sr.ReadToEnd (); If (fileString.Length> gt; 0) {Bytere = Enc. Gatebayts (file string); (Context ("X2"));}} Else {Console.} For the file (for int i = 0; i & lt; fileString.Length; i ++) (console WrightLine (file string [i] + byterere [i] WriteLine ("File is empty");}} Else {Console.WriteLine ("file" + file text + "does not exit");} Console.WriteLine ("Press any key to stop ..."); Console .ReadKey ();}}  

I have an ASCII-extended txt File and I need it to convert it to a byte array.

Then do not go to the text at all. If you just want to capture the bytes within a file, then it's really easy:

  byte [] data = file. Read AllBytes (filePath);  

At any time you find text by decoding the bytes, and then encoding with the same encoding to get that text on the byte, you should ask yourself if you want to Actually that text conversion is needed in the first place.


Comments