# FindPattern

int FindPattern (char *buffer, int startingIndex, int numberOfBytes, char *pattern, int caseSensitive, int startFromRight);

## Purpose

Searches a character buffer for a pattern of bytes. The string pattern specifies the pattern of bytes. FindPattern returns the position within the buffer where the pattern was found.

### Example

The following example returns 4, which is the index of the second of the three occurrences of ab in the string 1ab2ab3ab4. FindPattern skips the first occurrence because startingIndex is 3. Of the two remaining occurrences, FindPattern finds the leftmost occurrence because startFromRight is zero.

ndx = FindPattern ("1ab2ab3ab4", 3, -1, "AB", 0, 0);

The following example returns 7, which is the index of the rightmost occurrence of ab, because startFromRight is a nonzero value.

ndx = FindPattern ("1ab2ab3ab4", 3, -1, "AB", 0, 1);

## Parameters

Input
Name | Type | Description
buffer | string | Buffer to search for the pattern.
startingIndex | integer | Zero–based index specifying the location within buffer at which to begin searching for the pattern.
numberOfBytes | integer | Number of bytes to search. If numberOfBytes is –1, FindPattern searches the set of bytes that starts at position startingIndex of buffer up to the first ASCII NUL.
pattern | string | NUL–terminated string specifying the pattern of bytes to search for.
caseSensitive | integer | Specifies whether alphabetic characters must have the same case to be considered equal. If caseSensitive is zero, FindPattern compares alphabetic characters without regard to case. If caseSensitive is a nonzero value, FindPattern considers alphabetic characters equal only if they have the same case.
startFromRight | integer | Specifies whether to find the leftmost or rightmost occurrence of the pattern. If startFromRight is zero, FindPattern finds the leftmost occurrence of the pattern in the buffer. If startFromRight is a nonzero value, FindPattern finds the rightmost occurrence of the pattern in the buffer.

## Return Value

Name | Type | Description
ndx | integer | Index in buffer where FindPattern finds the first byte of the pattern. The index is zero–based and is relative to the first byte of the buffer variable.
| Note If FindPattern does not find the pattern in the buffer, the function returns –1.