How to use the like operator with special characters.

I am trying to use the Like operator in VB.net to check to see if the following characters exist within a string:

"(", "[", "{", ")", "]", "}"

The problem is that VB.net uses brackets "[]" to group a series of characters, and brackets are one of the characters that I am looking for in my string.

What is the syntax that I must use to successfully check for the above group of character's in my string including brackets?


Thank you in advance for your time.
NevSoFlyAsked:
Who is Participating?
 
ChloesDadConnect With a Mentor Commented:
The right bracket is not allowed in this context

to search for either of the 6 brackets it would look like this I have added spaces for visual effect


* [   (  [[]  {  )  }  ] *

to then find a ] you would do a new LIKE *]*

so the overall logic would be

IF string LIKE "*[([[]{)}]*" OR string LIKE "*]*"
0
 
Jim P.Connect With a Mentor Commented:
For square brackets try:
like "*" & Chr(91) & "*" & Chr(93) & "*" &

Open in new window


For squiggly brackets try:
like "*" & Chr(123) & "*" & Chr(125) & "*" &

Open in new window


Here's an ASCII table.
0
 
ChloesDadCommented:
To match the special characters left bracket ([), question mark (?), number sign (#), and asterisk (*), enclose them in square brackets. The right bracket (]) cannot be used within a group to match itself, but it can be used outside a group as an individual character.

eg [[], [?]. [#] and [*]
0
 
NevSoFlyAuthor Commented:
I read the Microsoft example too, but was having a hard time visualizing the syntax.  So if I included the right bracket would look something like [[({)}] []] ?
0
 
Jim P.Commented:
When you do it using the Chr function it is handled as a literal value and not as a special character that has to be escaped.
0
All Courses

From novice to tech pro — start learning today.