Re: String Comparison
- From: "Tigger" <mccreath@xxxxxxxxxxx>
- Date: Sun, 20 Apr 2008 23:56:02 +0930
"Qu" <quasar@xxxxxxxxxxxxx> wrote in message
news:ebdb36fc-16cb-4dca-a35f-b1bff580fad9@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.
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.
--
Tony
http://www.mccreath.org.uk
.
- References:
- String Comparison
- From: Qu
- String Comparison
- Prev by Date: Re: Displaying a set of questions
- Next by Date: Kenneth Cole Ladies Gold Tone Stainless Steel Camel Leather Watch KC2252 - Replica Watch Fake
- Previous by thread: Re: String Comparison
- Next by thread: Regular Expression Frustration
- Index(es):
Relevant Pages
|