halodu03de Posted June 3, 2009 Report Posted June 3, 2009 In VB when I write to a file, and what I write is fewer characters than what was originally there, I need it to clear the extra characters. For example, if I have 1234567 in a text box that was read from an offset in a file, and I change it to 55555 and write it to the same offset, it is 5555567 instead of 55555. Does anyone have any idea how to fix that?
Dark Slipstream Posted June 4, 2009 Report Posted June 4, 2009 You could use a Replace() method, I wrote one in my DLL, but this version hasn't been released yet. Here is some reference code, don't copy paste, it won't work unless you try to work with it. -.- Dim Filepath As String = "C:\test" Dim Binary As New Dark.Slipstream.OperatingSystem.Binary Dim OperatingSystem As New Dark.Slipstream.OperatingSystem Dim fi As New System.IO.FileInfo(Filepath ) Dim originalStr As String = "1234567" Dim Offset As Integer = CInt(OperatingSystem.ScanForString(Filepath, originalStr, 0) Dim Length As Integer = str.Length() Dim Beginning As Byte() = Binary.Read(Filepath, 0, Offset) Dim Ending As Byte() = Binary.Reader(Filepath, (Offset + Length), (CInt(fi.Length) - Offset)) Dim newStr As String = "55555" Dim AddByte As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(newStr) Dim tempByte As Byte() = OperatingSystem.CombineByteArray(AddByte, Beginning) Dim completeByte As Byte() = OperatingSystem.CombineByteArray(Ending, tempByte) Binary.Write(Filepath, completeByte) 'New function that will overwrite a file, and write completely new data. Ok so I lied, if you have my new DLL, that should actually work 100% lol... Wait until it's released, that is basically my Replace() function, just this one is double the size because I'm a little tired, and tried to make it more easily understandable.
halodu03de Posted June 4, 2009 Author Report Posted June 4, 2009 You could use a Replace() method, I wrote one in my DLL, but this version hasn't been released yet. Here is some reference code, don't copy paste, it won't work unless you try to work with it. -.- Dim Filepath As String = "C:\test" Dim Binary As New Dark.Slipstream.OperatingSystem.Binary Dim OperatingSystem As New Dark.Slipstream.OperatingSystem Dim fi As New System.IO.FileInfo(Filepath ) Dim originalStr As String = "1234567" Dim Offset As Integer = CInt(OperatingSystem.ScanForString(Filepath, originalStr, 0) Dim Length As Integer = str.Length() Dim Beginning As Byte() = Binary.Read(Filepath, 0, Offset) Dim Ending As Byte() = Binary.Reader(Filepath, (Offset + Length), (CInt(fi.Length) - Offset)) Dim newStr As String = "55555" Dim AddByte As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(newStr) Dim tempByte As Byte() = OperatingSystem.CombineByteArray(AddByte, Beginning) Dim completeByte As Byte() = OperatingSystem.CombineByteArray(Ending, tempByte) Binary.Write(Filepath, completeByte) 'New function that will overwrite a file, and write completely new data. Ok so I lied, if you have my new DLL, that should actually work 100% lol... Wait until it's released, that is basically my Replace() function, just this one is double the size because I'm a little tired, and tried to make it more easily understandable. Alright thanks a lot.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now