+ Reply to Thread
Results 1 to 2 of 2

Thread: Regular Expression

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    45

    Regular Expression

    I trying to improve a textbox that filters a gridview, by implementing an enhanced textbox that can identify AND, OR, NOT operators by searching for this keywords in the string the user inputs in the textbox.

    I am trying to use Regular Expression , but can`t figure it out .

    An example of what I want:
    Code:
    string = "String1 and String2 and String3 or String4 or not String5 and not String6"
    results in a split mode:
    String1 and
    String2 and
    String3 or
    String4 or not
    String5 and not
    String6

    This is because then I will take the first for example and replace with
    SomeTable.Name_Of_Build = String1' AND

    SomeTable.Name_Of_Build = 'String' AND .... so on

  2. #2
    You can try the below code :
    Code:
    string filter = "build1 and buil2 and build3 or build4 or not build5"
    list<string> filterTokens = filter.Split(new char[] {' '})
    
    string gridViewFilter = "";    
    bool notEqual = false;
    
    foreach(string token in filterTokens)
    {
       if(token == "and")
       {
          gridViewFilter += "and"
       }
       else if(token == "or")
       {
         gridViewFilter += "or"
       }
       else if(token == "not")
       {
          notEqual = true;
       }
       else if(notEqual)
       {
          gridViewFilter += "SomeTable.Name_Of_Build <> '" + token + "'";
          notEqual = false;
       }
       else
       {
          gridViewFilter += "SomeTable.Name_Of_Build <> '" + token + "'";
       }
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts