System.Windows.Forms.HexBox.Find C# (CSharp) Method

Find() public method

Searches the current ByteProvider
public Find ( byte bytes, long startIndex ) : long
bytes byte the array of bytes to find
startIndex long the start index
return long
        public long Find(byte[] bytes, long startIndex)
        {
            int match = 0;
            int bytesLength = bytes.Length;

            _abortFind = false;

            for(long pos = startIndex; pos < _byteProvider.Length; pos++)
            {
                if(_abortFind)
                    return -2;

                if(pos % 1000 == 0) // for performance reasons: DoEvents only 1 times per 1000 loops
                    Application.DoEvents();

                if(_byteProvider.ReadByte(pos) != bytes[match])
                {
                    pos -= match;
                    match = 0;
                    _findingPos = pos;
                    continue;
                }

                match++;

                if(match == bytesLength)
                {
                    long bytePos = pos-bytesLength+1;
                    Select(bytePos, bytesLength);
                    ScrollByteIntoView(_bytePos+_selectionLength);
                    ScrollByteIntoView(_bytePos);

                    return bytePos;
                }
            }

            return -1;
        }