Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Article Writing
  4. wildcards

wildcards

Scheduled Pinned Locked Moved Article Writing
regexhelpquestion
2 Posts 2 Posters 17 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rajiv Ramachandran
    wrote on last edited by
    #1

    Hi all, I need an algorith to wildcard match two strings similar to what happens when you do a dir *.* - I`d require it to support both * and ? - nothing too fancy !! Appreciate any help in this !! Thanks in advance !! Rajiv

    G 1 Reply Last reply
    0
    • R Rajiv Ramachandran

      Hi all, I need an algorith to wildcard match two strings similar to what happens when you do a dir *.* - I`d require it to support both * and ? - nothing too fancy !! Appreciate any help in this !! Thanks in advance !! Rajiv

      G Offline
      G Offline
      Gertjan Schuurmans
      wrote on last edited by
      #2

      Hi, this code should do the trick. It's an adapted function from SysInternals' FileMon application. Regards, Gertjan Schuurmans Amsterdam //--------------------------------------------------- // MatchWildCard // //Parameters // LPCTSTR pszWildCard // LPCTSTR pszFileName // //Returns // BOOL // //Remarks // // MatchWildCard tests whether the given filename matches the wildcard. pszWildCard // can contain * and ? special characters. // BOOL MatchWildCard(LPCTSTR pszWildCard, LPCTSTR pszFileName) { #define UpCase(ch) ((ch) >= 'a' && (ch) <= 'z' ? (ch) - 'a' + 'A' : (ch)) TCHAR chFile, chWild; // End of pattern? if (!*pszWildCard) { return FALSE; } // If we hit a wild card, do recursion if (*pszWildCard == '*') { pszWildCard++; while (*pszFileName && *pszWildCard) { chFile = UpCase(*pszFileName); chWild = UpCase(*pszWildCard); // See if this substring matches if (chWild == chFile || chFile == '*') { if (MatchWildCard(pszWildCard + 1, pszFileName + 1)) { return TRUE; } } // Try the next substring pszFileName++; } // See if match condition was met return (*pszWildCard == 0 || *pszWildCard == '*'); } // Do straight compare until we hit a wild card while (*pszFileName && *pszWildCard != '*') { chFile = UpCase(*pszFileName); chWild = UpCase(*pszWildCard); if (chWild == chFile || chWild == '?') { pszWildCard++; pszFileName++; } else { return FALSE; } } // If not done, recurse if (*pszFileName) { return MatchWildCard(pszWildCard, pszFileName); } // Make sure its a match return (*WildCard == 0 || *WildCard == '*'); ================== The original message was: Hi all,
      I need an algorith to wildcard match two strings similar to what happens when you do a dir *.* - I`d require it to support both * and ? - nothing too fancy !!

      Appreciate any help in this !!
      Thanks in advance !!

      Rajiv

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups