Solved

How to use the like operator with special characters.

Posted on 2013-06-02
5
639 Views
Last Modified: 2013-06-02
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.
0
Comment
Question by:NevSoFly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 200 total points
ID: 39214260
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
 
LVL 15

Expert Comment

by:ChloesDad
ID: 39214470
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
 

Author Comment

by:NevSoFly
ID: 39214512
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
 
LVL 38

Expert Comment

by:Jim P.
ID: 39214523
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
 
LVL 15

Accepted Solution

by:
ChloesDad earned 300 total points
ID: 39214540
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question