Manual:DIL Manual/strncmp()
Jump to navigation
Jump to search
strncmp()
Function (integer). Compares the first characters of two strings, minding upper and lower case.
strncmp(s1 : string, s2 : string, n : integer)
Like strcmp(), but looks at no more than the first
n characters of each string. Use it to test how a string begins when case matters.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s1 | string | The first string. |
| s2 | string | The second string. |
| n | integer | How many characters to compare at most. |
Returns
Integer: 0 when the first n characters are the same (or both strings end sooner,
alike), less than 0 when s1 sorts before s2, more than 0 when after.
Test the sign only.
A string variable that was never set counts as "". It fails when a string
argument is a failed value.
Notes
n0 always gives 0. A negativencompares the whole strings.- A shorter string sorts first:
strncmp("ab", "abc", 3)is less than 0. - For a test that ignores case,
"word" in sandleft()with
== are simpler.
Example
dilbegin integer is_god_tag(s : string);
code
{
return (strncmp(s, "GOD:", 4) == 0);
}
dilend
Tells whether a text begins with the capitals GOD:, so that god:
doesn't count.