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

定義

文字列比較の結果により、-1、0、または 1 のいずれかを返します。

public static int StrComp (string? String1, string? String2, Microsoft.VisualBasic.CompareMethod Compare = Microsoft.VisualBasic.CompareMethod.Binary);
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 設定により比較の種類を決定します。

戻り値

Int32

次のいずれかの値です。

IfStrComp の戻り値
String1String2 よりも先に来る-1
String1String2 は等価です。0
String1String2 の後に来る1

例外

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 引数の設定は以下の通りです。

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

適用対象

こちらもご覧ください