strstr, strstri - find substring in string

SYNOPSIS

<strstr $needle $haystack [$mode]>
<strstri $needle $haystack [$mode]>


DESCRIPTION
The strstr function finds the first occurrence of each $needle value in each $haystack value.

The optional $mode argument is a stringcomparemode-style (here) compare mode to use; the default is the current apicp stringcomparemode, with "ignorecase" added for strstri. The $mode values are used in the same order as $haystack values. The $mode argument was added in version 6.


DIAGNOSTICS
strstr and strstri return N*H values (N and H being the number of values in $needle and $haystack), i.e. there is exactly one return value for each $needle/$haystack combination. Each return value is the character index into the $haystack value where the corresponding $needle value was first found (0 for first character), or -1 if the $needle value was not found. The first N return values are for the first $haystack value (in $needle order), the next N return values are for the second $haystack value, etc. $mode is a stringcomparemode value.


EXAMPLE

<$haystack = "This is a test." "Is that?" "My island.">
<strstr "is" $haystack>

The return values in $ret would be 2, -1 and 3.


CAVEATS
Note that the arguments to strstr are in opposite order from the C version. The strstr and strstri functions were added Feb. 5 1997.

Note that the offsets returned are character-based, not byte-based. For byte offsets, ensure iso-8859-1 is part of $mode (e.g. pass +iso-8859-1), as character offsets in ISO-8859-1 are always the same as byte offsets - unlike the default UTF-8-based mode.

Text is compared according to apicp stringcomparemode (with "ignorecase" for strstri), or the $mode argument.


SEE ALSO
substr


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.