3

I have a problem using "like" operator.

I want to find strings, in a table, like "Address #123" or "Address #56778" or "Address #2b". So, I wrote this in my code:

If m_Table.Rows(i).Item("NOTE").ToString Like "*ADDRESS #*" Then

But, the code reads the "#" as a wildcard, not a simple character.

How can I rewrite my code to make it read the # as a simple character, not a wildcard?

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
djobert
  • 55
  • 1
  • 3
  • 7
  • It made corrections to my questions, there are * wildcard used in the operator, because the address is stored somewhere in a "note" field. So, it doesn't start with "Address #" – djobert Jul 30 '14 at 15:42

1 Answers1

5

You can escape the special characters [ ? # * by enclosing them in square brackets [ ]. For more information see the Like Operator reference.

If m_Table.Rows(i).Item("NOTE").ToString Like "*ADDRESS [#]*" Then

Another option is to use StartsWith, EndsWith or Contains methods of the string class instead.

If m_Table.Rows(i).Item("NOTE").ToString().Contains("ADDRESS #") Then
Bjørn-Roger Kringsjå
  • 9,849
  • 6
  • 36
  • 64