Need WILDCARD search to find rows in a DataTable

G

Guest

The rowExpression documentation states

--------------- begin copy -----------
A wildcard is allowed at the beginning and end of a pattern, or
at the end of a pattern, or at the beginning of a pattern. For example:
"ItemName LIKE '*product*'"
"ItemName LIKE '*product'"
"ItemName LIKE 'product*'"
Wildcards are not allowed in the middle of a string. For example, 'te*xt' is
not allowed.
(...)


--------------- end copy -----------

But I do need to find "TE?XT" and "TE*XT". Cna nayone suggest what I can do
- even if I search row by row - how can I match a string on a wildcard?

Thanks
 
M

Miha Markic [MVP C#]

Hi,

va said:
The rowExpression documentation states

--------------- begin copy -----------
A wildcard is allowed at the beginning and end of a pattern, or
at the end of a pattern, or at the beginning of a pattern. For example:
"ItemName LIKE '*product*'"
"ItemName LIKE '*product'"
"ItemName LIKE 'product*'"
Wildcards are not allowed in the middle of a string. For example, 'te*xt'
is
not allowed.
(...)


--------------- end copy -----------

But I do need to find "TE?XT" and "TE*XT". Cna nayone suggest what I can
do
- even if I search row by row - how can I match a string on a wildcard?

When looping through rows you could use string.IndexOf methods to find both
pieces or more powerfull but slower RegEx class (regular expressions).
 
G

Guest

Thanks Miha

I am not a regex expert. How do I translate the following into a regex
expression?

"TEXT?.E*E"

where the ? character and * could be any number of letters or numbers?
 
J

john smith

va said:
Thanks Miha

I am not a regex expert. How do I translate the following into a regex
expression?

"TEXT?.E*E"

where the ? character and * could be any number of letters or numbers?

I second Miha's advice. I would use a regular expression to match the
rows, unless there are too many rows and that it's too complex of an
expression, in which case it would be too resource intensive to do.

Also, you seem to use ? and * interchangeably which is uncommon -
perhaps even in reverse from the normal "conventions" (? for 1 char
which you're using to match several in your example it seems, and * to
match any number which in your example you seem to want to match to a
single character)

If you want to learn about regular expressions, you can google it -
there are TONS of great references/sites (even wikipedia has an exntry
about it), there are some great little utilities (some are free) to
learn about them and test them out, there are some books about it, some
sites have collections of pre-made regex'es (regexlib.com), and there's
even some cheat sheets you can find (ilovejackdaniels.com has a nice one).
 
G

Guest

Hi John,

It would appear odd but in my case, I am matching file name using wildcard
characters so it is very possible someone would use both. One simple example,
if you had a bunch of music files like MP3 and MP4 you would want to use the
? so that you do not pick up files like MyFile.MP3.OLD.
 
J

john smith

va said:
Hi John,

It would appear odd but in my case, I am matching file name using wildcard
characters so it is very possible someone would use both. One simple example,
if you had a bunch of music files like MP3 and MP4 you would want to use the
? so that you do not pick up files like MyFile.MP3.OLD.
Using wildcards doesn't appear odd, and using MP? to match those
extensions seems normal (whereas MP* would match .MP3.OLD), but your
previous example seemed "reversed": E*E for extension which will
normally match E_anything_in_here_E and TEXT? which would usually only
match TEXT + 1 more character, hence matching TEXT9.EXYZE but not
TEXT10.EXE. That's all I meant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top