Strings.StrComp メソッドとは? わかりやすく解説

Strings.StrComp メソッド

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

名前空間: Microsoft.VisualBasic
アセンブリ: Microsoft.VisualBasic (microsoft.visualbasic.dll 内)
構文構文

Public Shared Function StrComp
 ( _
    String1 As String, _
    String2 As String, _
    <OptionalAttribute> Optional Compare As
 CompareMethod = CompareMethod.Binary _
) As Integer
Dim String1 As String
Dim String2 As String
Dim Compare As CompareMethod
Dim returnValue As Integer

returnValue = Strings.StrComp(String1, String2, Compare)
public static int StrComp
 (
    string String1,
    string String2,
    [OptionalAttribute] CompareMethod Compare
)
public:
static int StrComp (
    String^ String1, 
    String^ String2, 
    [OptionalAttribute] CompareMethod Compare
)
public static int StrComp
 (
    String String1, 
    String String2, 
    /** @attribute OptionalAttribute() */ CompareMethod Compare
)
public static function StrComp
 (
    String1 : String, 
    String2 : String, 
    Compare : CompareMethod
) : int

パラメータ

String1

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

String2

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

Compare

省略可能。文字列比較の種類を指定します。Compare が省略されている場合、Option Compare 設定により比較の種類を決定します。

戻り値
String1 が String2 の前を並べ替える場合、StrComp は -1 を返します。String1 が String2 に等しい場合、StrComp は 0 を返します。String1 が String2 の後ろを並べ替える場合、StrComp は 1 を返します。

解説解説
使用例使用例

この例では、StrComp 関数を使用して、文字列比較の結果を返しています。3 つ目の引数を省略した場合、Option Compare ステートメントで定義された比較の種類、またはプロジェクトの既定の比較の種類が実行されます。

' 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 after TestStr2. Returns -1.
TestComp = StrComp(TestStr1, TestStr2, CompareMethod.Binary)
' TestStr2 sorts before TestStr1. Returns 1.
TestComp = StrComp(TestStr2, TestStr1)
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

Strings.StrComp メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Strings.StrComp メソッドのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS