Note that there are some explanatory texts on larger screens.

plurals
  1. POSave HEX data to file
    primarykey
    data
    text
    <p>I'm having some problems saving the edited data to the original file... I want to save my string from textBox1 to the file it was loaded from.</p> <p>Here is my "Load" function:</p> <pre><code>public static string getItemName(int index) { FileStream str = File.OpenRead(Directory.GetCurrentDirectory() + ybi); BinaryReader breader = new BinaryReader(str); breader.BaseStream.Position = itemSectionStart; byte[] itemSection = breader.ReadBytes(itemSectionEnd); string itemName = BitConverter.ToString(itemSection, 808 * index + 7, 64).Replace("00", "").Replace("-", ""); return hex2ascii(itemName); } </code></pre> <p>Here is my "Save" function:</p> <pre><code>public static bool setItemName(int index, string _FileName, byte[] _ByteArray) { try { System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); _FileStream.Write(_ByteArray, 808 * index + 7, _ByteArray.Length); _FileStream.Close(); return true; } catch (Exception _Exception) { MessageBox.Show(Convert.ToString(_Exception.Message)); } return false; } </code></pre> <p>Now, I think here is where the problem is, in the conversion from my HEX String to ByteArray...</p> <pre><code>private byte[] HexStringToByteArray(string hexString) { int hexStringLength = hexString.Length; byte[] b = new byte[hexStringLength / 2]; for (int i = 0; i &lt; hexStringLength; i += 2) { int topChar = (hexString[i] &gt; 0x40 ? hexString[i] - 0x37 : hexString[i] - 0x30) &lt;&lt; 4; int bottomChar = hexString[i + 1] &gt; 0x40 ? hexString[i + 1] - 0x37 : hexString[i + 1] - 0x30; b[i / 2] = Convert.ToByte(topChar + bottomChar); } return b; } private void button2_Click(object sender, EventArgs e) { int index = listBox1.SelectedIndex; string hex = ""; foreach (char c in textBox1.Text) { int tmp = c; hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString())); } writeValuePositions.setItemName(index, save_FileName, HexStringToByteArray(hex.ToUpper())); } </code></pre> <p>The byteArray that gets sent to writeValuePositions.setItemName isnt right I think... I get this Exception </p> <pre><code>--------------------------- --------------------------- Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection. --------------------------- OK --------------------------- </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload