Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Overwrite one section of binary file

Overwrite one section of binary file

Scheduled Pinned Locked Moved C#
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tommazzo
    wrote on last edited by
    #1

    Hi! I have a binary file that contains strings one after the other and I want to replace a string at offset x. The existing string is, let's say 10 bytes long, but the new one is 12 bytes long. How do I replace the old string at position x without overwriting the first 2 bytes of the next string and without rewriting the entire binary file from offset x. Thanks already in advance!

    G D 2 Replies Last reply
    0
    • T tommazzo

      Hi! I have a binary file that contains strings one after the other and I want to replace a string at offset x. The existing string is, let's say 10 bytes long, but the new one is 12 bytes long. How do I replace the old string at position x without overwriting the first 2 bytes of the next string and without rewriting the entire binary file from offset x. Thanks already in advance!

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You don't. --- b { font-weight: normal; }

      1 Reply Last reply
      0
      • T tommazzo

        Hi! I have a binary file that contains strings one after the other and I want to replace a string at offset x. The existing string is, let's say 10 bytes long, but the new one is 12 bytes long. How do I replace the old string at position x without overwriting the first 2 bytes of the next string and without rewriting the entire binary file from offset x. Thanks already in advance!

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You can't. You MUST rewrite the entire file. Read the the part up to the point where you are replacing the string, write it to a new file. Append the new string, then read the file from the point after the string your replacing and append that to the new file. There is NO other way to do this. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        T 1 Reply Last reply
        0
        • D Dave Kreskowiak

          You can't. You MUST rewrite the entire file. Read the the part up to the point where you are replacing the string, write it to a new file. Append the new string, then read the file from the point after the string your replacing and append that to the new file. There is NO other way to do this. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          T Offline
          T Offline
          tommazzo
          wrote on last edited by
          #4

          I see. Thanks for your help guys!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups