design patterns - VB.NET Delete all bytes after a specific one in a file -


in vb.net program have delete bytes come after these ones: 48534853 untill it's end (i know corrupt file).

how can that? wrote functions replace pattern 1 , locate specific bytes, don't know how wipe out after pattern.

use filestream.setlength method.

using stream = new filestream(path, filemode.open, fileaccess.write)     filestream.setlength(newlength) end using 

--

try this:

dim pattern integer() = new integer() {&h48, &h53, &h48, &h53} dim p integer = 0 'position in pattern. using fs = new filestream("path", filemode.open, fileaccess.readwrite)     pos integer = 0 fs.length - 1         dim b integer = fs.readbyte()         if b = pattern(p)             p += 1             if p = pattern.length                 fs.setlength(pos - pattern.length + 1)                 return             end if         else             p = 0         end if     next end using 

note fs.readbyte() returns byte integer.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -