|
-
Jul 31st, 2012, 04:59 PM
#1
Thread Starter
Member
Find and replace HEX values
Hi Guys, I hope somone can help me understand Hex a little,
I need to find and replace C3 91 with D1,
The code i have only changes 1 value IE C3 with D1
Code:
Dim fs As New FileStream("C:\Users\nick\Desktop\test.txt", FileMode.Open, FileAccess.ReadWrite)
Dim b As Integer = fs.ReadByte()
While b <> -1
If b = &HC3 Then
fs.Seek(-1, SeekOrigin.Current)
fs.WriteByte(&HD1)
End If
b = fs.ReadByte()
End While
fs.Close()
fs.Dispose()
can someone help me achieve this.
Also can someone tell me what &H means ??
Cheers guys
-
Jul 31st, 2012, 05:18 PM
#2
Re: Find and replace HEX values
&H is just a means of indicating that what follows should be interpreted as a hexidecimal number. Without that, C3 would look like a string that you had forgotten to enclose in quotes, or the name of a function or variable that wasn't defined. In either case, you would get an error for that line. By adding the &H, the compiler knows what to do with what you entered. Other languages use other conventions. All the C derived languages use 0x rather than &H, so you will see 0x in lots of examples. They are the same thing, though.
It sounds like you want to replace two bytes with one. Is that really what you want to do? That change seems improbable, as it would change the number of bytes in the file. It would also be a whole lot easier to replace two with two, especially since you already know how to do it. Replacing two with one would pretty much require that you create a new file which consists of all the bytes up to the bytes you want to replace, followed by your one byte (D1) followed by all the bytes after the ones you want to replace. You can't very well just create a hole in an existing file. There has to be something there, even if it is 0.
My usual boring signature: Nothing
 
-
Jul 31st, 2012, 05:28 PM
#3
Thread Starter
Member
Re: Find and replace HEX values
Hi Shaggy Hiker
Yes my goal is to replace 2 values with one, just so you know its not a program ar anything like that im changing its going to be either a text or csv file, so it should not corrupt the file.
the reason i cant simply do a normal find and replace in the text file is because when i replace Ñ with Ñ in the text file it still screw's up the process of the text file because even thow they look the same the hex values are still diffrent, now when i do the find and replace in Hxd it works first time, i am only making the program to speed the process up abit.
hope this clears things up abit :-)
-
Jul 31st, 2012, 09:17 PM
#4
Re: Find and replace HEX values
Yeah, it won't mess up a text file, but you still can't replace two values with one as a simple process. You will need to read in the file, take everything up to the point you want to replace, then add in the correct byte, then get all the bytes after the replacement, and once you have all that concatenated together, you would then write out the file again.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|