Strings.StrComp(String, String, CompareMethod) メソッド

定義

文字列比較の結果に基づいて、-1、0、または 1 を返します。

public static int StrComp(string String1, string String2, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
static member StrComp : string * string * Microsoft.VisualBasic.CompareMethod -> int
Public Function StrComp (String1 As String, String2 As String, Optional Compare As CompareMethod = Microsoft.VisualBasic.CompareMethod.Binary) As Integer

パラメーター

String1
String

必須。 任意の有効な String 式。

String2
String

必須。 任意の有効な String 式。

Compare
CompareMethod

オプション。 文字列比較の種類を指定します。 Compareを省略すると、Option Compare設定によって比較の種類が決まります。

返品

以下のどちらかの値 :

もしStrComp の戻り値
String1 の前に並べ替えます String2-1
String1 == String20
String1 sorts after String21

例外

Compare 値が無効です。

この例では、 StrComp 関数を使用して文字列比較の結果を返します。

' Defines variables.
Dim testStr1 As String = "ABCD"
Dim testStr2 As String = "abcd"
Dim testComp As Integer
' The two strings sort equally. Returns 0.
testComp = StrComp(testStr1, testStr2, CompareMethod.Text)
' testStr1 sorts before testStr2. Returns -1.
testComp = StrComp(testStr1, testStr2, CompareMethod.Binary)
' testStr2 sorts after testStr1. Returns 1.
testComp = StrComp(testStr2, testStr1, CompareMethod.Binary)

注釈

文字列は、最初の文字で始まる英数字の並べ替え値によって比較されます。 バイナリ比較、テキスト比較、並べ替え順序の詳細については、「 Option Compare ステートメント」を参照してください。

Compare引数の設定は次のとおりです。

定数 Description
Binary 文字の内部バイナリ表現から派生した並べ替え順序に基づいて、バイナリ比較を実行します。
Text システムの LocaleID 値によって決定される、大文字と小文字を区別しないテキストの並べ替え順序に基づいて、テキスト比較を実行します。

適用対象

こちらもご覧ください