MEMINDEX

MEMINDEX returns a size_t 1 value that indicates the starting position within a buffer of a specified substring.

With three arguments, the function's syntax is as follows:

Read syntax diagramSkip visual syntax diagram
>>-MEMINDEX--(--p--,--n--,--x--)-------------------------------><

p
Address of buffer to be searched.
n
Length of buffer to be searched.
x
String-expression to use as the target of the search.

With four arguments, the function's syntax is as follows:

Read syntax diagramSkip visual syntax diagram
>>-MEMINDEX--( -p--,--n--,--q--,--m--)-------------------------><

p
Address of first buffer to be searched.
n
Length of first buffer to be searched.
q
Address of second buffer to use as the target of the search.
m
Length of second buffer to use as the target of the search.

The buffer lengths must be nonnegative and must have a computational type. The buffer lengths are converted to type size_t.

With three arguments, the target string-expression must have type CHARACTER (including PICTURE), GRAPHIC, or WIDECHAR. The buffer length is interpreted as the number of units of that string type.

With four arguments, the buffer lengths specify a number of bytes and the search performed is a character search.

For a VARYING, VARYING4, or VARYINGZ string X and string Y, the function MEMINDEX(ADDRDATA(X), LENGTH(X), Y) will return the same value as INDEX(X, Y).

Example

  dcl cb(128*1024) char(1);
  dcl wb(128*1024) widechar(1);
  dcl pos fixed bin(31);
  /* 128K bytes searched for the character string 'test' */
  pos = memindex( addr(cb), stg(cb), 'test' );
  /* 256K bytes searched for the string 'test' as widechar */
  pos = memindex( addr(wb), stg(wb), wchar('<') );





Published: 23 December 2018