strncmp, strnicmp - compare strings, fixed length


<strncmp $a $b $len [$mode]>
<strnicmp $a $b $len [$mode]>

strncmp and strnicmp behave like strcmp and strcmpi, respectively. However, each takes a third parameter $len which gives the maximum number of characters to compare against the corresponding value of $b. If $len has fewer values than $b, its last value is re-used; if it has no values, infinity is assumed (e.g. strcmp behavior).

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

strncmp and strnicmp return A*B integer values (A and B being the number of values of $a and $b).


<strncmp "this" "the" 2>

The return value in $ret would be 0.

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

Lengths in $len count characters, not bytes. For byte counting, add "iso-8859-1" to $mode.

strcmp, strcmpi

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