末尾の文字列と一致するかどうか判断する
VB6 では、EndsWith のようなメソッドがありませんが、Right$ 関数を使えば容易に可能です。以下のような関数を自作します。
サンプルコード
以下にサンプルコードを示します。
VB6.0
' ------------------------------------------------------------------------------- ' 末尾の文字列と一致しているかどうかを判断します。 ' ' @Param stTarget シーク対象となる文字列。 ' @Param stSeek シークする文字列。 ' @Return 末尾の文字列と一致する場合は True。それ以外は False。 ' ------------------------------------------------------------------------------- Public Function EndsWith(ByVal stTarget As String, ByVal stSeek As String) As Boolean EndsWithString = (Right$(stTarget, Len(stSeek)) = stSeek) End Function
使用例は以下のようになります。
VB6.0
' 必要な変数を宣言する
Dim stTarget As String
stTarget = "Hirotoshi Naka"
' 末尾の文字列と一致するかどうかを判断する
If EndsWith(stTarget, "Naka") Then
Call MsgBox("末尾の文字列と一致します")
End If
