名前空間
変種
操作

strcoll

From cppreference.com
< c‎ | string‎ | byte
ヘッダー <string.h> で定義
int strcoll( const char* lhs, const char* rhs );

現在のロケール(LC_COLLATE カテゴリで定義される)に従って、2つのヌル終端バイト文字列を比較します。

目次

[編集] パラメータ

lhs, rhs - 比較するヌル終端バイト文字列へのポインタ

[編集] 戻り値

  • lhsrhs より小さい(先行する)場合、負の値。
  • 0 if lhsrhs等しい場合。
  • lhsrhs より大きい(後続する)場合、正の値。

[編集] 注釈

照合順序は辞書順です。文字の(その同等クラスにおける)位置は、大文字・小文字やバリアントよりも優先されます。同等クラス内では、小文字は対応する大文字よりも前に照合され、アクセント記号付き文字にはロケール固有の順序が適用される場合があります。一部のロケールでは、文字のグループが単一の照合単位として比較されます。たとえば、チェコ語の "ch""h" の後に、"i" の前に来ます。ハンガリー語の "dzs""dz" の後に、"g" の前に来ます。

[編集]

#include <locale.h>
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    setlocale(LC_COLLATE, "cs_CZ.utf8");
    // Alternatively, ISO-8859-2 (a.k.a. Latin-2)
    // may also work on some OS:
    // setlocale(LC_COLLATE, "cs_CZ.iso88592");
 
    const char* s1 = "hrnec";
    const char* s2 = "chrt";
 
    printf("In the Czech locale: ");
    if (strcoll(s1, s2) < 0)
        printf("%s before %s\n", s1, s2);
    else
        printf("%s before %s\n", s2, s1);
 
    printf("In lexicographical comparison: ");
    if (strcmp(s1, s2) < 0)
        printf("%s before %s\n", s1, s2);
    else
        printf("%s before %s\n", s2, s1);
}

出力

In the Czech locale: hrnec before chrt
In lexicographical comparison: chrt before hrnec

[編集] 参考文献

  • C23標準 (ISO/IEC 9899:2024)
  • 7.24.4.3 The strcoll function (p: TBD)
  • C17標準 (ISO/IEC 9899:2018)
  • 7.24.4.3 The strcoll function (p: TBD)
  • C11標準 (ISO/IEC 9899:2011)
  • 7.24.4.3 The strcoll function (p: 366)
  • C99標準 (ISO/IEC 9899:1999)
  • 7.21.4.3 The strcoll function (p: 329)
  • C89/C90標準 (ISO/IEC 9899:1990)
  • 4.11.4.3 The strcoll function

[編集] 関連項目

現在のロケールに従って2つのワイド文字列を比較する
(関数) [編集]
strcmp が strcoll と同じ結果になるように文字列を変換する
(関数) [編集]
wcscmpwcscollと同じ結果を生成するようにワイド文字列を変換する
(関数) [編集]
2つの文字列を比較する
(関数) [編集]
English 日本語 中文(简体) 中文(繁體)