Reputation: 11
I'm trying to make a search function for one of my programs, my plan is to let users search content with something like this
((network || system) && (ip || dns || bios)) && (version || name)
so whenever a string matches this search term like
NETWORK: ****** DNS: ******* NAME: *******
or
SYSTEM BIOS VERSION: ****
it will recognize it.
But i can't figure out how to implement this.
I thought about working through the whole search term and splitting it up to it's pieces but since i don't know how many AND or OR's are going to be in there i don't know how to do it.
Upvotes: 1
Views: 93
Reputation: 9782
You can do two things:
Is is not too hard to write a simple parser yourself (if you know enough about the theory behind it). Else use a ready made toolkit like @Patrick suggested (ANTLR) which involves quite some learning curve also.
Upvotes: 1
Reputation: 157108
In order to do this, you need more than just some string comparison. Actually you are looking for a parser that can parse statements and form something understandable out of it, whether that is for you.
I would recommend to take a look at ANTLR, which is a parser/lexer. It has templates for C# too.
Upvotes: 3