Main Index : Reference :

memmem()


Description

Locates the first occurrence of a phrase of bytes within another byte array, optionally beginning the search at a certain position.

Definition

[int] memmem([bytes] mem,[bytes] phrase)
[int] memmem([bytes] mem,[bytes] phrase,[int] pos)

Parameters

mem is the byte array.
phrase is the search phrase.
pos is the optional start position of the search.

Return Value

memmem() returns the position of the first occurence of phrase within the byte array mem. If the third parameter is passed, only the part of mem that is after the position pos is searched. If no match is found, the return value is -1.

Remember: The first element of a byte array is at position 0.

Example

// See also the examples for strstr().

// Locates and extracts an element in a data file.

var file = loadDataFile();

var signature = getElementSignature(); 
var length = getElementLength();

var pos = memmem(file,signature);
var element = memmid(file,pos,length); 

See Also

[bytes], memins(), memset(), memmid(), memadd()