Click here to Skip to main content
15,886,806 members
Home / Discussions / C#
   

C#

 
GeneralRe: Trouble with Invocation, serial port Pin
introuble218-Sep-08 1:49
introuble218-Sep-08 1:49 
GeneralRe: Trouble with Invocation, serial port Pin
leppie18-Sep-08 3:14
leppie18-Sep-08 3:14 
AnswerRe: Trouble with Invocation, serial port Pin
Alan N18-Sep-08 1:46
Alan N18-Sep-08 1:46 
GeneralRe: Trouble with Invocation, serial port Pin
introuble218-Sep-08 2:07
introuble218-Sep-08 2:07 
GeneralRe: Trouble with Invocation, serial port Pin
Searril18-Sep-08 9:01
Searril18-Sep-08 9:01 
GeneralRe: Trouble with Invocation, serial port Pin
introuble219-Sep-08 2:02
introuble219-Sep-08 2:02 
GeneralRe: Trouble with Invocation, serial port Pin
Searril19-Sep-08 10:14
Searril19-Sep-08 10:14 
QuestionUser searchbox and RegEx best-practice Pin
ArneKruger17-Sep-08 21:56
ArneKruger17-Sep-08 21:56 
Hi there!

I am currently developing a small database frontend for private use. Obviously I want to search the various collections of business objects I pull out of the database. The search term is entered by the user and should allow for dos-stlyed wildcards (*, ?, #). In the old VB days there was this nice "like" operator (don't flame on me, please!) but since I moved on to c# there is no such thing.

I realize that Regular Expressions are the way to go, but I am unshure on how to implement these old wildcards. Pure RegEx are not an option since I find these to be much to complex for the casual user.
My current solution involves simple find & replace to transform a wildcard-expression into a valid RegEx:
<br />
criteria = criteria.Replace("?", @"\w(1)");<br />
criteria = criteria.Replace("#", @"\d(1)");<br />
criteria = criteria.Replace("*", @".*");<br />
<br />
string regex;<br />
RegexOptions options = RegexOptions.Singleline;<br />
<br />
if (IgnoreCase)<br />
 options = options | RegexOptions.IgnoreCase;<br />
<br />
 if (WholeWortsOnly)<br />
 {<br />
   regex = string.Format(System.Globalization.CultureInfo.InvariantCulture, @"(^{0}$|^{0}\s+|\s+{0}$|\s+{0}\s+)", criteria);<br />
 }<br />
 else<br />
 {<br />
   regex = criteria;<br />
 }<br />
<br />
if (criteria.Length == 0)<br />
{<br />
  regex = @"^.{0}$";<br />
}<br />
<br />
RegEx matchRegex = new Regex(regex, options);<br />
<br />

Obviously there are quite some possibilities for the user to bust this code: entering characters with RegEx-specific meaning (^, \, $ ...) will lead to exceptions or unexpected behaviour.

My question is: how do you tackle such thing?

best regards
Arne
AnswerRe: User searchbox and RegEx best-practice Pin
leppie17-Sep-08 22:27
leppie17-Sep-08 22:27 
GeneralRe: User searchbox and RegEx best-practice Pin
ArneKruger17-Sep-08 23:37
ArneKruger17-Sep-08 23:37 
QuestionProper use of Tag property Pin
Mycroft Holmes17-Sep-08 21:47
professionalMycroft Holmes17-Sep-08 21:47 
AnswerRe: Proper use of Tag property Pin
N a v a n e e t h17-Sep-08 21:55
N a v a n e e t h17-Sep-08 21:55 
GeneralRe: Proper use of Tag property Pin
Mycroft Holmes17-Sep-08 22:08
professionalMycroft Holmes17-Sep-08 22:08 
AnswerRe: Proper use of Tag property Pin
Pete O'Hanlon17-Sep-08 21:58
mvePete O'Hanlon17-Sep-08 21:58 
GeneralRe: Proper use of Tag property Pin
Mycroft Holmes17-Sep-08 22:00
professionalMycroft Holmes17-Sep-08 22:00 
GeneralRe: Proper use of Tag property Pin
N a v a n e e t h17-Sep-08 22:03
N a v a n e e t h17-Sep-08 22:03 
GeneralRe: Proper use of Tag property Pin
Pete O'Hanlon17-Sep-08 22:32
mvePete O'Hanlon17-Sep-08 22:32 
GeneralRe: Proper use of Tag property Pin
N a v a n e e t h17-Sep-08 23:50
N a v a n e e t h17-Sep-08 23:50 
Questionauthentication issue Pin
George_George17-Sep-08 21:40
George_George17-Sep-08 21:40 
AnswerRe: authentication issue Pin
leppie17-Sep-08 22:21
leppie17-Sep-08 22:21 
GeneralRe: authentication issue Pin
George_George17-Sep-08 23:01
George_George17-Sep-08 23:01 
GeneralRe: authentication issue Pin
leppie17-Sep-08 23:06
leppie17-Sep-08 23:06 
GeneralRe: authentication issue Pin
George_George17-Sep-08 23:24
George_George17-Sep-08 23:24 
GeneralRe: authentication issue Pin
leppie17-Sep-08 23:40
leppie17-Sep-08 23:40 
GeneralRe: authentication issue Pin
George_George18-Sep-08 0:01
George_George18-Sep-08 0:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.