Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use the like operator with special characters.

Posted on 2013-06-02
5
Medium Priority
?
804 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
  • 2
  • 2
5 Comments
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 800 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 1200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

927 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