473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

implementing wildcard match function

I need to implement vfp function which uses * and ? wildcards:

static bool Like( cExpression1, cExpression2)

cExpression1

Specifies the character expression that Like( ) compares with cExpression2.
cExpression1 can contain the wildcards such as * and ?. The question mark
(?) matches any single character in cExpression2 and the asterisk (*)
matches any number of characters. You can mix any number of wildcards in any
combination in cExpression1.

cExpression2
Specifies the character expression LIKE( ) compares with cExpression1.

returns true on wildcards match.

How to implement this ?

Andrus

Sep 26 '08 #1
6 3095
The simplest and fastest way to do this would be to write a tiny assembly in
VB, and use the VB Like operator, which does exactly what you want. Put one
static (Shared in VB) function into it, that takes the two strings and
returns a Boolean.

E.g.:

Public Shared Function VBLike(Byval oneString as String, byval otherString
as String) as Boolean

Return oneString Like otherString

End Function

I hope this doesn't set off a flame war, and I'm sure that there's also a
way to do it with Regex, but it's a quick way to get what you want.

Actually, I'll confess that this response is a little tongue-in-cheek, but
what can I say :-) Pretty quick someone will be along with the Regex
equivalent. If I don't see such a response after a while I'll work one up
for you in C#.

Tom Dacon
Dacon Software Consulting

"Andrus" <ko********@hot.eewrote in message
news:uE**************@TK2MSFTNGP04.phx.gbl...
>I need to implement vfp function which uses * and ? wildcards:

static bool Like( cExpression1, cExpression2)

cExpression1

Specifies the character expression that Like( ) compares with
cExpression2.
cExpression1 can contain the wildcards such as * and ?. The question mark
(?) matches any single character in cExpression2 and the asterisk (*)
matches any number of characters. You can mix any number of wildcards in
any
combination in cExpression1.

cExpression2
Specifies the character expression LIKE( ) compares with cExpression1.

returns true on wildcards match.

How to implement this ?

Andrus

Sep 27 '08 #2
Tom,
Public Shared Function VBLike(Byval oneString as String, byval otherString
as String) as Boolean

Return oneString Like otherString

End Function
Thank you.
I have C# 2008 Express. It does not allow to program in VB.
I think there must be some method in some net dll whose call in generated by
VB compiler for like operator .

Do you know what it this method name so I can call it from C# code ?
Or is there vb -c# converter which converts this code?

Andrus.

Sep 27 '08 #3
Andrus, here is the method name to use when you're calling from C#:

Microsoft.VisualBasic.CompilerServices.Operators.L ikeString

However if what you're running is C# 2008 Express you may not actually have
the VB assemblies at all. Cross your fingers and go to the references dialog
and see what you find.

Otherwise, I'd pursue a solution with the Regex class in
System.Text.RegularExpressions. Try these sites to start:

http://www.regular-expressions.info/

http://regexlib.com/

One of those sites has a Regex tester that you can use to try out your
attempts.

Regex syntax is ugly and finicky, but very powerful. It's a "language" only
a programmer could love, and only a few do. I suspect that far less than one
percent of C# programmers are even competent with Regex expressions, let
alone fluent. However the rules you need to implement are simple, so perhaps
you might find your way to a suitable Regex expression without too much
difficulty.

Good luck,
Tom Dacon

"Andrus" <ko********@hot.eewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Tom,
>Public Shared Function VBLike(Byval oneString as String, byval
otherString as String) as Boolean

Return oneString Like otherString

End Function

Thank you.
I have C# 2008 Express. It does not allow to program in VB.
I think there must be some method in some net dll whose call in generated
by VB compiler for like operator .

Do you know what it this method name so I can call it from C# code ?
Or is there vb -c# converter which converts this code?

Andrus.

Sep 27 '08 #4
Andrus, here's a link to a discussion of implementing the VB Like
functionality with Regex. It may be useful to you.

http://groups.google.com/group/micro...ba3e39a6c2711f

Tom Dacon
Dacon Software Consulting

"Andrus" <ko********@hot.eewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Tom,
>Public Shared Function VBLike(Byval oneString as String, byval
otherString as String) as Boolean

Return oneString Like otherString

End Function

Thank you.
I have C# 2008 Express. It does not allow to program in VB.
I think there must be some method in some net dll whose call in generated
by VB compiler for like operator .

Do you know what it this method name so I can call it from C# code ?
Or is there vb -c# converter which converts this code?

Andrus.

Sep 27 '08 #5
Andrus, here's a link to a discussion of implementing the VB Like
functionality with Regex. It may be useful to you.

http://groups.google.com/group/micro...ba3e39a6c2711f
THank you.
This referest to internal method not recommended for use from applications.

How to implement this in pure C# ?

Andrus.

Sep 28 '08 #6
Andrus, one of the messages in the discussion contains a link to a web site
with code that does it. The latter part of the message thread discusses
changes and extensions to the supplied code.

Good luck,
Tom Dacon
Dacon Software Consulting

"Andrus" <ko********@hot.eewrote in message
news:eB*************@TK2MSFTNGP05.phx.gbl...
>Andrus, here's a link to a discussion of implementing the VB Like
functionality with Regex. It may be useful to you.

http://groups.google.com/group/micro...ba3e39a6c2711f

THank you.
This referest to internal method not recommended for use from
applications.

How to implement this in pure C# ?

Andrus.

Sep 28 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Robert Brown | last post by:
I have researched newsgroups and the web very thoroughly and unsuccessfully for a solution to what I believe is a very common problem. I know it's easy to do wildcard match against data in DB...
1
by: deko | last post by:
I have a form where users can enter a string with asterisks to perform a wildcard search. Currently, the string entered by the user looks like this: *somestring* The purpose is to match any...
2
by: deko | last post by:
I'm trying to use a textbox to search and display records as each letter is typed in - similar to the behavior of a combo box. But for some reason I can't seem to get the wildcard search character...
3
by: george.lengel | last post by:
Hello experts, I have been struggling for days to solve this problem and every suggestion I find via Google does not work for me. There is probably a solution out there that will do what I want,...
78
by: wkehowski | last post by:
The python code below generates a cartesian product subject to any logical combination of wildcard exclusions. For example, suppose I want to generate a cartesian product S^n, n>=3, of that...
11
by: google | last post by:
I need a simple wildcard pattern matching function written in JS. I have wrestled with regular expresions but frankly am struggling to come up with anything less than an epic function of many lines...
11
by: ABC | last post by:
How to rename files with support wildcard ?
3
by: Lars Eighner | last post by:
Is it possible, accidentally or on purpose, to pass a wildcard to this function that would have the effect of deleting many or all rows (shortname is a unique, non-null field)? function...
4
by: kcddoorman | last post by:
I'm trying to make a multi criteria server filter and everything works fine when filtering for strings. When I add a number field to the filterable set I run into problems. Here is the VBScript I'm...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.