strncmp, strnicmp

strncmp, strnicmp — compare two strings and return a numeric result.

Syntax

strncmp (string1, string2, length)
strnicmp (string1, string2, length)

		

Arguments

string1

The first string.

string2

The second string.

length

The maximum length of the comparison.

Returns

An integer < 0 if string1 is lexically less than string2 to the given length; 0 if the two strings are equal up to the given length; and an integer > 0 if string1 is lexically greater than string2 up to the given length.

Description

The strncmp function compares two strings and returns a numeric result indicating whether the first string is lexically less than, greater than, or equal to the second string. The comparison will carry on for not more than length characters of the shorter string. The strnicmp function is the case-insensitive version of strncmp.

Example

Gamma> strncmp("hello","helicopter",4);
3
Gamma> strncmp("hello","help",3);
0
Gamma> strncmp("Hello","help", 3);
-32
Gamma> strnicmp("Hello","help", 3);
0
Gamma> 
		

See Also

strcmp, stricmp