Click here to Skip to main content
15,892,768 members
Home / Discussions / C#
   

C#

 
AnswerRe: Style vs Performance Pin
PIEBALDconsult21-Dec-10 17:58
mvePIEBALDconsult21-Dec-10 17:58 
GeneralRe: Style vs Performance Pin
Roger Wright21-Dec-10 18:09
professionalRoger Wright21-Dec-10 18:09 
GeneralRe: Style vs Performance Pin
PIEBALDconsult22-Dec-10 3:31
mvePIEBALDconsult22-Dec-10 3:31 
GeneralRe: Style vs Performance Pin
Roger Wright22-Dec-10 4:01
professionalRoger Wright22-Dec-10 4:01 
GeneralRe: Style vs Performance Pin
PIEBALDconsult22-Dec-10 14:28
mvePIEBALDconsult22-Dec-10 14:28 
GeneralRe: Style vs Performance Pin
Roger Wright22-Dec-10 14:39
professionalRoger Wright22-Dec-10 14:39 
AnswerRe: Style vs Performance Pin
Luc Pattyn21-Dec-10 18:25
sitebuilderLuc Pattyn21-Dec-10 18:25 
AnswerRe: Style vs Performance Pin
Pete O'Hanlon21-Dec-10 22:28
mvePete O'Hanlon21-Dec-10 22:28 
Well, for a start, if you want to continue using this, make Classify static. There's no real reason for it to be an instance method. Then, I would consider creating a Dictionary of the patterns. You could rewrite this as:
C#
private enum DataMatches
{
  Header = 0,
  Blank = 1,
  Total = 2,
  Sum = 3,
  NewData = 4,
  Data = 5,
  Unmatched = 99
}
        
private static void SetupRegex()
{
  if (dataPatterns != null && dataPatterns.Count > 0) return;

  dataPatterns = new Dictionary<string, DataMatches>();
  dataPatterns.Add(@"^(D|""D|T|S|I|E|""Z)", DataMatches.Header);
  dataPatterns.Add(@"^$", DataMatches.Blank);
  dataPatterns.Add(@"^""To", DataMatches.Total);
  dataPatterns.Add(@"^""\d\d/\d\d/\d\d\d\d"","""",", DataMatches.Sum);
  dataPatterns.Add(@"^""\d\d/\d\d/\d\d\d\d"",", DataMatches.NewData);
  dataPatterns.Add(@"^"""",""\w", DataMatches.Data);
}

private static DataMatches Classify(string s)
{
  SetupRegex();
  foreach (KeyValuePair<string, DataMatches> kvp in dataPatterns)
  {
    if (Regex.IsMatch(kvp.Key)) return kvp.Value;
  }
  return DataMatches.Unmatched;
}

I'm not a stalker, I just know things. Oh by the way, you're out of milk.

Forgive your enemies - it messes with their heads


My blog | My articles | MoXAML PowerToys | Onyx


GeneralRe: Style vs Performance Pin
PIEBALDconsult22-Dec-10 3:09
mvePIEBALDconsult22-Dec-10 3:09 
AnswerRe: Style vs Performance Pin
Keith Barrow21-Dec-10 22:56
professionalKeith Barrow21-Dec-10 22:56 
GeneralRe: Style vs Performance Pin
PIEBALDconsult22-Dec-10 3:19
mvePIEBALDconsult22-Dec-10 3:19 
QuestionMessage Removed Pin
21-Dec-10 16:45
Aseem Sharma21-Dec-10 16:45 
AnswerRe: Register a 32 bit ATL service on Windows7-64 bit? Pin
Dave Kreskowiak21-Dec-10 18:21
mveDave Kreskowiak21-Dec-10 18:21 
GeneralRe: Register a 32 bit ATL service on Windows7-64 bit? Pin
Aseem Sharma21-Dec-10 19:12
Aseem Sharma21-Dec-10 19:12 
QuestionI'm looking for ideas or examples on programmatically reading the contents inside of a remote desktop window Pin
turbosupramk321-Dec-10 11:22
turbosupramk321-Dec-10 11:22 
AnswerRe: I'm looking for ideas or examples on programmatically reading the contents inside of a remote desktop window Pin
PIEBALDconsult21-Dec-10 15:59
mvePIEBALDconsult21-Dec-10 15:59 
GeneralRe: I'm looking for ideas or examples on programmatically reading the contents inside of a remote desktop window Pin
turbosupramk321-Dec-10 16:24
turbosupramk321-Dec-10 16:24 
GeneralRe: I'm looking for ideas or examples on programmatically reading the contents inside of a remote desktop window Pin
turbosupramk321-Dec-10 16:31
turbosupramk321-Dec-10 16:31 
QuestionASP.NET C# set GridView Column htmlencode to false from C# Pin
al3xutzu0021-Dec-10 9:29
al3xutzu0021-Dec-10 9:29 
Questionc# and sql recursive data query Pin
peropata21-Dec-10 5:45
peropata21-Dec-10 5:45 
AnswerRe: c# and sql recursive data query Pin
J4amieC21-Dec-10 6:01
J4amieC21-Dec-10 6:01 
AnswerRe: c# and sql recursive data query Pin
Not Active21-Dec-10 8:21
mentorNot Active21-Dec-10 8:21 
AnswerRe: c# and sql recursive data query Pin
PIEBALDconsult21-Dec-10 8:58
mvePIEBALDconsult21-Dec-10 8:58 
GeneralRe: c# and sql recursive data query Pin
peropata21-Dec-10 9:19
peropata21-Dec-10 9:19 
GeneralRe: c# and sql recursive data query Pin
PIEBALDconsult21-Dec-10 10:10
mvePIEBALDconsult21-Dec-10 10:10 

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.