Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleWrite functions to determine whether a string starts or ends with a substring in Visual Basic 6
DescriptionThis example shows how to write functions to determine whether a string starts or ends with a substring in Visual Basic 6
KeywordsStartsWith, EndsWith, substring
CategoriesStrings, 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.
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated