Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to use the like operator with special characters.

Posted on 2013-06-02
5
Medium Priority
?
742 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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