So Ive been searching and reading MS docs on how to best read binary data (hex) and convert it to text. All was going good on the file Im reading in 40 bytes at a time as thats the delimiter for each record. Several records in it gets thrown off by 1 byte. Turns out its 0A (line feed) or a 10 decimal and then each loop gets thrown off by an increment character position.
Im using Encoding.ASCII.GetBytes but am wondering if the encoding is part of the problem? I read in the entire file with a StreamReader and .ReadToEnd into a public string variable and then chunk up the string from there.
Is there another method I can use to read a position and length in the file instead of the string var? Maybe something simple Im overlooking.
Thanks
Code:try { int offSet = 49; for (int i = 0; i < aSNumberOfFields; i++) { byte[] chunk; chunk = Encoding.ASCII.GetBytes(SfileRaw.Substring(offSet, 40)); if (chunk.Length == 40) { DumpFieldBytes(chunk); } else return; offSet += 41; } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error: LoadFieldNames"); }





Reply With Quote