Re: String Comparison

Tech-Archive recommends: Fix windows errors by optimizing your registry



"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





.



Relevant Pages

  • Re: searching for the highest index within a directory
    ... (I used to write code in the Ada programming language... ... Because "testFile_34" is a string, ... there is no way to compare them as numbers. ... means we look at the first character in each string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Delimiting problems
    ... > So how can I delimit the " character? ... Now when I have a piece of string such as ... If you want to compare against several values, ...
    (comp.lang.c)
  • Re: Quandry with the following C code (Intermediate)
    ... It doesn't do a compare the usual way. ... a string with Unicode characters over 256 in it. ... This tallies the number of occurrences of each separate character value ... of the same character at all in the first string, ...
    (comp.lang.c)
  • Re: Numbers higher but the computer dosnt think so
    ... You haven't shown us how L is declared (String, Integer, Single, etc.). ... ASCII characters and String comparisons are done character by character. ... decide on how to compare these dissimilar things. ... also use the CDbl function to make the comparison, ...
    (comp.lang.basic.visual.misc)
  • Escaping problem using Regular Expression
    ... string s = re.Replace; ... regular expression return without filter out any ... However if I remove or change the position of "]" to be the first character, ... I totally do not understand how this regular expression escaping works. ...
    (microsoft.public.dotnet.languages.csharp)