Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / April 2008

Tip: Looking for answers? Try searching our database.

String Comparison

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Qu - 16 Apr 2008 04:20 GMT
Hi everyone.

I'm trying to make an application in which people can type in their
own selection filter for an external application. For this, I need to
be able to compare a string to a value in much the same way a search
box does: "*" for a wildcard, AND and OR as their respective
comparisons, greater than> and less than<, etc...

Here's an example. The user could type this into the textbox:
">100 And <180 Or 240"
Which would be compared with a number and return true if the number
was between 100 and 180, or was 240.

Another example:
"*BRACE* Or SINGLE_BEAM"
Which would be compared with a string and return true if the string
contained the substring BRACE or exactly matched SINGLE_BEAM.

Is there an easy way to do this, or am I going to have to go through
the string character by character to extract the information? [crosses
fingers]

Thanks,
Qu.
Cor Ligthert[MVP] - 16 Apr 2008 04:35 GMT
Qu,

In my idea is mostly using the split the first way I try, probably is your
problem however a real Regex problem.

http://msdn2.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx

Cor

> Hi everyone.
>
[quoted text clipped - 20 lines]
> Thanks,
> Qu.
Qu ~ Quasar Tri-Delta ~ - 16 Apr 2008 05:37 GMT
On Apr 16, 1:35 pm, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nl>
wrote:
> Qu,
>
[quoted text clipped - 4 lines]
>
> Cor

Thanks for the reference, I haven't used regular expressions or the
regex class before. I'll have to study them a bit, but they seem to be
fairly close to what I'm looking for. I just need to work out how
they're used and what they're capable of...
Ignacio Machin ( .NET/ C# MVP ) - 16 Apr 2008 16:18 GMT
> Hi everyone.
>
[quoted text clipped - 20 lines]
> Thanks,
> Qu.

Hi,

No, there is no easy way of doing that. You need to parse the string
(not an easy task per se) and generate a Regex struct to later use to
compare
Qu ~ Quasar Tri-Delta ~ - 16 Apr 2008 22:54 GMT
On Apr 17, 1:18 am, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.com> wrote:

> > Hi everyone.
>
[quoted text clipped - 28 lines]
>
> - Show quoted text -

Looking into the help files on regular expressions I began to suspect
as much. Oh well... at least its a function I can write once and use
over and over. :) Thanks for your help.
Tigger - 20 Apr 2008 15:26 GMT
> Hi everyone.
>
[quoted text clipped - 20 lines]
> Thanks,
> Qu.

Maybe linq could be a solution. I'm still on .Net 2.0 so I'm not familiar
with its limitations. (or the select method in a dataset has some
abilities).

If this is to gather data in a database, then maybe your database supports
this sort of expression.

Otherwise your asking quite a lot as the system that parses these
expressions has to understand boolean logic across numbers and strings plus
partial string matching. And it has to cope with user error!

Generally this means you need to implement a parser, and this is quite
involved

I found the following a good tool to develop one in .Net...
http://www.devincook.com/goldparser/
Far better than going through, character by character!

It sounds like you interface is not GUI based. If it was then one way would
be to make the GUI provide an editor that controls the filter logic a user
can enter. In this way you can enforce the syntax making writing the filter
code easier. In my GUIs i tend to let the user do from/to for number fields
and partial string matching for text fields. I combine them together (AND)
and this covers most peoples needs without getting complex.

Signature

Tony
http://www.mccreath.org.uk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.