471,354 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,354 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 3007
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Robert Brown | last post: by
3 posts views Thread by george.lengel | last post: by
11 posts views Thread by google | last post: by
3 posts views Thread by Lars Eighner | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.