strfind()

strfind()

Description

Search for a sub-string in a string.

Syntax

strfind(string[], sub[], ignorecase, index);

Parameters

Variable

Input

Variable

Input

string[]

The string in which you wish to search for sub-strings.

sub[]

The sub-string to search for.

ignorecase

true - case is ignored during the comparison

false - case is matched during the comparison

index

The character position in string to start searching. Set to 0 to start from the beginning of the string.

Returns

The function returns the character index of the first occurrence of the string sub in string,

or −1 if no occurrence was found.

If an occurrence was found, you can search for the next occurrence by calling strfind again and set the parameter offset to the returned value plus one.

Function call example

String search example
new data1[10] = [1, 8, 4, 8, 15, 14, 23, 42, 78, 21]; new data2[6] = [4, 8, 15, 14, 23, 42]; new array1[6]=''Same''; new array2[15]=''diffSamediff''; new data3; new data4;  main(){ data3 = strfind(data1, data2, true, 0) //compare data array data1 with data2. data3 value will be: 2; since matching array element of data1 and data2 is no.2 (count starts at 0) data4 = strfind(array2, array1, true, 0) //compare two arrays. data4 value will be: 4; since matching array element of array2 and array1 is no.4 (count starts at 0)  while(1){ Delay(100); } }

Notes and Warnings

This function searches for a sub-string in a string, optionally ignoring the character case and optionally starting at an offset in the string.