|
|
Title | Write functions to determine whether a string starts or ends with a substring in Visual Basic 6 |
Description | This example shows how to write functions to determine whether a string starts or ends with a substring in Visual Basic 6 |
Keywords | StartsWith, EndsWith, substring |
Categories | Strings, Tips and Tricks |
|
|
Visual Basic .NET's String class includes useful StartsWith and EndsWith methods. These are not complicated but they are handy. (The only really annoying omission from this class is a method that works like the Left$ function provided in Visual Basic 6.)
This example shows Visual Basic 6 versions.
|
|
' Return True if test_string ends with target.
Private Function EndsWith(ByVal test_string As String, _
ByVal target As String) As Boolean
EndsWith = (Right$(test_string, Len(target)) = target)
End Function
' Return True if test_string starts with target.
Private Function StartsWith(ByVal test_string As String, _
ByVal target As String) As Boolean
StartsWith = (Left$(test_string, Len(target)) = target)
End Function
|
|
Whenever you change the text in either text box, the program displays whether the test text starts or ends with the target text.
|
|
|
|
|
|