名前空間
変種
操作

strcoll

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

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

目次

[編集] 引数

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

[編集] 戻り値

lhsrhs より小さい (前に来る) 場合は負の値。

lhsrhs等しい場合は 0

lhsrhs より大きい (後に来る) 場合は正の値。

[編集] ノート

照合順序は辞書順です。 アルファベットの文字 (等価クラス) の位置は大文字小文字や変種よりも高い優先度を持ちます。 等価クラス内では、小文字は同等な大文字よりも前に照合され、ダイアクリティカルマーク付きの文字にはロケール固有の順序が適用されるかもしれません。 ロケールによっては、文字のグループが単一の照合単位として比較されます。 例えば、チェコ語の "ch""h" より後、 "i" より前に、ハンガリー語の "dzs""dz" より後、 "g" より前に来ます。

[編集]

#include <stdio.h>
#include <string.h>
#include <locale.h>
 
int main(void)
{
    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

[編集] 参考文献

  • C11 standard (ISO/IEC 9899:2011):
  • 7.24.4.3 The strcoll function (p: 366)
  • C99 standard (ISO/IEC 9899:1999):
  • 7.21.4.3 The strcoll function (p: 329)
  • C89/C90 standard (ISO/IEC 9899:1990):
  • 4.11.4.3 The strcoll function

[編集] 関連項目

現在のロケールに従ってワイド文字列を比較します
(関数) [edit]
strcoll と同じ結果を strcmp で得られるように文字列を変換します
(関数) [edit]
wcscoll と同じ結果を wcscmp で得られるようにワイド文字列を変換します
(関数) [edit]
2つの文字列を比較します
(関数) [edit]