GLib.strncasecmp
Description: Reference for GLib.strncasecmp

### Function

# GLibstrncasecmp

deprecated: 2.2

#### Declaration [src]

    gint
    g_strncasecmp (
      const gchar* s1,
      const gchar* s2,
      guint n
    )

#### Description [src]

A case-insensitive string comparison, corresponding to the standard `strncasecmp()` function on platforms which support it. It is similar to `g_strcasecmp()` except it only compares the first `n` characters of the strings.

Deprecated since: 2.2

The problem with `g_strncasecmp()` is that it does the comparison by calling `toupper()`/`tolower()`. These functions are locale-specific and operate on single bytes. However, it is impossible to handle things correctly from an internationalization standpoint by operating on bytes, since characters may be multibyte. Thus `g_strncasecmp()` is broken if your string is guaranteed to be ASCII, since it is locale-sensitive, and it’s broken if your string is localized, since it doesn’t work on many encodings at all, including UTF-8, EUC-JP, etc.

There are therefore two replacement techniques: `g_ascii_strncasecmp()`, which only works on ASCII and is not locale-sensitive, and `g_utf8_casefold()` followed by `strcmp()` on the resulting strings, which is good for case-insensitive sorting of UTF-8.

#### Parameters

`s1`

  Type: `const gchar*`

  String to compare with `s2`.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`s2`

  Type: `const gchar*`

  String to compare with `s1`.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`n`

  Type: `guint`

  The maximum number of characters to compare.

#### Return value

Type: `gint`

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