public int ascii_ncasecmp (string s2, size_t n)

Compare s1 and s2, ignoring the case of ASCII characters and any characters after the first n in each string.

Unlike the BSD strcasecmp function, this only recognizes standard ASCII letters and ignores the locale, treating all non-ASCII characters as if they are not letters.

The same warning as in ascii_casecmp applies: Use this function only on strings known to be in encodings where bytes corresponding to ASCII letters always represent themselves.

Example: Compare n bytes of strings, ignoring the case:

public static int main (string[] args) {
string str1 = "YOU WILL __OBEY__ THE DALEKS!";
string str2 = "You will //obey// the daleks!";

// Compare first 9 characters:
// Output: ``0``
int res = str1.ascii_ncasecmp (str2, 9);
print ("%d\n", res);

// Compare first 10 characters:
// Output: ``48``
res = str1.ascii_ncasecmp (str2, 10);
print ("%d\n", res);

return 0;

valac --pkg glib-2.0 string.ascii_ncasecmp.vala



string to compare with s1


number of characters to compare


string to compare with s2


0 if the strings match, a negative value if s1 < s2, or a positive value if s1 > s2 .