Click here to Skip to main content
15,893,790 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# code for summing up Pin
Alan Balkany18-Sep-08 4:21
Alan Balkany18-Sep-08 4:21 
GeneralRe: C# code for summing up Pin
Angelinna18-Sep-08 4:44
Angelinna18-Sep-08 4:44 
QuestionUsing Microsoft.Office.Interop.Excell.dll to modify .xls file Pin
mcnam17-Sep-08 23:26
mcnam17-Sep-08 23:26 
Questionvarchar(max) vs varchar(50) Pin
Mogaambo17-Sep-08 23:03
Mogaambo17-Sep-08 23:03 
AnswerRe: varchar(max) vs varchar(50) Pin
leppie17-Sep-08 23:08
leppie17-Sep-08 23:08 
AnswerRe: varchar(max) vs varchar(50) Pin
Mogaambo17-Sep-08 23:26
Mogaambo17-Sep-08 23:26 
GeneralRe: varchar(max) vs varchar(50) Pin
leppie17-Sep-08 23:42
leppie17-Sep-08 23:42 
GeneralRe: varchar(max) vs varchar(50) Pin
Pete O'Hanlon18-Sep-08 0:30
mvePete O'Hanlon18-Sep-08 0:30 
QuestionHow to show event of a user control in property window Pin
Guru Call17-Sep-08 22:50
Guru Call17-Sep-08 22:50 
AnswerRe: How to show event of a user control in property window Pin
Simon P Stevens17-Sep-08 23:30
Simon P Stevens17-Sep-08 23:30 
QuestionTrouble with Invocation, serial port Pin
introuble217-Sep-08 22:41
introuble217-Sep-08 22:41 
AnswerRe: Trouble with Invocation, serial port Pin
leppie17-Sep-08 22:51
leppie17-Sep-08 22:51 
GeneralRe: Trouble with Invocation, serial port Pin
introuble218-Sep-08 0:31
introuble218-Sep-08 0:31 
GeneralRe: Trouble with Invocation, serial port Pin
leppie18-Sep-08 0:35
leppie18-Sep-08 0:35 
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 

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.