1
1
12rbah2020-12-25 13:05:49
Algorithms
12rbah, 2020-12-25 13:05:49

Is there a fast algorithm for finding a substring with gaps in a string?

Perhaps he asked the question incorrectly, the essence is that there is a signature 0xFF 0xDD ?? ?? 0xFF, where question marks can be any characters, a signature is searched in a large file, and if these three characters occur in any substring of 5 characters, the only thing that came to mind is to find the signature 0xFF 0xDD save 5 bytes (string) to an array and then another once separately go over this array and check for the presence of these characters.
Just thought mb there is a standard algorithm for this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2020-12-25
@12rbah

There is a standard mechanism. It's called regular expressions.
However, in this particular case, it is not clear why you need to save something in a separate array. You just need to find 0xFF 0xDDmove three bytes to the right and check that there is 0xFF. Something like this (pseudocode):

for(int i = 0; i < data.size - 4; i++) {
  if (data[i] == 0xFF && data[i+1] == 0xDD && data[i+4] == 0xFF) {
    // нашёл
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question