Re: Help with Regex and trying to mimic the VB "like" comparison
From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 06/15/04
- Next message: Robert Misiak: "Re: C# Time zone"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: {simple} int SomeNumber to 1 byte array"
- In reply to: Niki Estner: "Re: Help with Regex and trying to mimic the VB "like" comparison"
- Next in thread: Andrew Baker: "Re: Help with Regex and trying to mimic the VB "like" comparison"
- Reply: Andrew Baker: "Re: Help with Regex and trying to mimic the VB "like" comparison"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 15 Jun 2004 14:09:25 -0400
Niki, Beeeeeeeeeeeeves, and Andrew,
The Like functionality is exposed through the Microsoft.VisualBasic
namespace. Add a reference to Microsoft.VisualBasic.dll, and then call the
static StrLike method on the StringType class in the
Microsoft.VisualBasic.CompilerServices namespace.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
"Niki Estner" <niki.estner@cube.net> wrote in message
news:eQWjNivUEHA.3336@TK2MSFTNGP11.phx.gbl...
> After a brief look, I think this code won't work for strings containing
> backslashes, braces, or any other Regex-metacharacters.
> I'd suggest using Regex.Escape(...) to escape all the meta-characters in
the
> pattern, and then replacing "\*" to ".*", and "\?" to ".", and adding the
> "^"/"$" prefix/suffix.
>
> Niki
>
> PS: Maybe your users would be glad if they had the choice to use the whole
> power of Regex's, too (optionally, of course). Like in the Search-Replace
> dialog of VS.
>
> "Andrew Baker" <webmaster@vbusers.com> wrote in
> news:c19b84e5.0406150720.1fb221c3@posting.google.com...
> > FYI have managed to bodge something together below which seems to work:
> >
> >
>
http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=25&PostID=1&NumReplies=0
> >
> > andrew
> >
> > "Beeeeeeeeeeeeves" <Beeeeeeeeeeeeves@discussions.microsoft.com> wrote in
> message news:<DB0F13A1-8FC8-4210-A888-E312CA820A56@microsoft.com>...
> > > You can use regexes, just allow the pattern the user types be the
> pattern for the regex, but with a few precautions:
> > > 1) Any characters they type that are regex escapes, you'll need to
> prefix them with \ to let the regex know they are literals, but beware
that
> you may not want to allow these in the filename anyway.
> > > See
> > >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconRegularExpressionsLanguageElements.asp
> (watch for wordwrap)
> > > 2)
> > >
> > > "Andrew Baker" wrote:
> > >
> > > > I am trying to write a function which provides my users with a file
> > > > filter. The filter used to work just using the VB "Like"
comparision,
> > > > but I can't find the equivilant in C#. I looked at RegEx.IsMatch but
> > > > it behaves quite differently. Is there a way I can mimic the DOS
> > > > filtering of filenames (eg. "*.*" or "*" returns all files, "*.xls"
> > > > returns all excel files, "workbook*" returns all files begining with
> > > > "workbook" etc)?
> > > >
> > > > thanks in advance...
> > > >
> > > > andrew
> > > >
>
>
- Next message: Robert Misiak: "Re: C# Time zone"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: {simple} int SomeNumber to 1 byte array"
- In reply to: Niki Estner: "Re: Help with Regex and trying to mimic the VB "like" comparison"
- Next in thread: Andrew Baker: "Re: Help with Regex and trying to mimic the VB "like" comparison"
- Reply: Andrew Baker: "Re: Help with Regex and trying to mimic the VB "like" comparison"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|