Friday, February 18, 2011

Like Operator - VB.NET

This example uses the Like operator to compare a string to a pattern. The result is a Boolean value representing whether the string fits the pattern.

Dim myCheck As Boolean
myCheck = "F" Like "F"   ' Does "F" match "F"? Returns True.
myCheck = "F" Like "f"   ' Does "F" match "f"? Returns False.
myCheck = "F" Like "FFF"   ' Does "F" match "FFF"? Returns False.
myCheck = "aBBBa" Like "a*a"   ' Does "aBBBa" have a "a" at the
   ' beginning, an "a" at the end, and any number of characters in
   ' between? Returns True.
myCheck = "F" Like "[A-Z]"   ' Does "F" occur in the set of
   ' characters from A to Z? Returns True.
myCheck = "F" Like "[!A-Z]"     ' Does "F" NOT occur in the set of
   ' characters from A to Z? Returns False.
myCheck = "a2a" Like "a#a"     ' Does "a2a" begin and end with an
   ' "a" and have any single-digit number inbetween? Returns True.
myCheck = "aM5b" Like "a[L-P]#[!c-e]" ' Does "aM5b" fit the following
   ' pattern: Begins with "a", has and character from the set L through
   ' P, followed byb any single-digit number, and finally contains any
   ' character excluded from the character set c through e. Returns True.
myCheck = "BAT123khg" Like "B?T*"  ' Does "BAT123khg" fit the
   ' following pattern: Begins with "B", followed by any single
   ' character, followed by a "T" and finally zero or more characters
   ' of any type. Returns True.
myCheck = "CAT123khg" Like "B?T*"  ' Does "CAT123khg" fit the
   ' following pattern: Begins with "B", followed by any single
   ' character, followed by a "T" and finally zero or more characters
   ' of any type. Returns False.
------------------------------------------
from : http://msdn.microsoft.com/en-us/library/swf8kaxw(v=vs.71).aspx

No comments:

Post a Comment