VBS(VBScript)サポート&サンプルTOPへ

VBS(VBScript)による文字列比較し判定をする方法を紹介

文字列比較し判定をする方法。StrComp関数を使用。
StrComp(string1, string2[, compare])


※1 StrComp の戻り値

string1 は string2 未満 -1
string1 と string2 は等しい 0
string1 は string2 を超える 1
string1 または string2 は Null 値 Null 値

※2 引数 compare の設定値

0 バイナリ モードで比較
1 テキスト モードで比較


サンプルソース



(入力)

Dim MyStr1, MyStr2, MyComp
MyStr1 = "ABCD"
MyStr2 = "abcd"
MyComp = StrComp(MyStr1, MyStr2, 1)
Wscript.Echo MyComp
MyComp = StrComp(MyStr1, MyStr2, 0)
Wscript.Echo MyComp
MyComp = StrComp(MyStr2, MyStr1)
Wscript.Echo MyComp


(出力)

0
-1
1



  

戻る




Copyright (C) VBS(VBScript)サポート&サンプル by wannko All Rights Reserved.
お問合せ先 ⇒ nachiko★wannko.net(★を@に変更して下さい。)