so I am creating a piece of software that in short, has a list of original byte sequences and new sequences that those bytes need to be changed into, kinda like this in text form "original location(currently irrelevant as sequence can be in different places) $ 56,69,71,73,75,77 : 56,69,71,80,50,54"
I already have code that works fine, however there can be up to 600+ of these sequences to find and change and in some cases it is taking a really really long time 15 mins +, i think it is down to how long it is taking to find the sequences to them change so i am trying to find a better way to do this as currently it is unusable due to how long it takes.
I have copied the whole code for this function below in hopes one of you kind souls can have a look and help =)
Dim originalbytes() As Byte
Dim fd As OpenFileDialog = New OpenFileDialog() fd.Title = "Select the file" fd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*" fd.FilterIndex = 2 If fd.ShowDialog() = DialogResult.OK Then TextBox2.Text = fd.FileName originalbytes = File.ReadAllBytes(fd.FileName) End If Dim x As Integer = 0 Dim y As Integer = 0 Dim textbox1array() = TextBox1.Lines Dim changedbytes() = originalbytes Dim startvalue As Integer = 0 Dim databoxarray() As String Dim databoxarray2() As String While x < textbox1array.Length - 1 'for each change to make databoxarray = textbox1array(x).Replace(" $ ", vbCr).Replace(" : ", vbCr).Split databoxarray2 = databoxarray(1).Replace(",", vbCr).Split Dim databox2bytes() As String = databoxarray2 'copy original bytes line to databox2 lines y = 0 While y < (originalbytes.Length - databox2bytes.Length) 'repeat for all bytes in ori file - size of data to find If originalbytes(y) = databox2bytes(0) Then startvalue = y Dim z As String = 1 Dim samebytecounter As Integer = 1 While z < databox2bytes.Length 'repeat for all ori bytes If originalbytes(y + z) = databox2bytes(z) Then samebytecounter = samebytecounter + 1 End If z = z + 1 End While If samebytecounter = databox2bytes.Length Then 'same original data found, make changes Dim bytestoinsert() As String = databoxarray(2).Replace(",", vbCr).Split Dim t As Integer = 0 While t < bytestoinsert.Length changedbytes(startvalue + t) = bytestoinsert(t) t = t + 1 End While End If End If y = y + 1 End While x = x + 1 End While File.WriteAllBytes(TextBox2.Text & " modified", changedbytes)
originalbytes. If this is working code, maybe it would be better to post this question on codereview