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. The Lounge
  3. Friday Programming Quiz [modified]

Friday Programming Quiz [modified]

Scheduled Pinned Locked Moved The Lounge
delphihtmldatabasedebuggingxml
44 Posts 17 Posters 2 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.
  • M Matt Gerrans

    Dave Kreskowiak wrote:

    But, then again, I wrote the "psuedo" in my head after looking at the problem for all of 15 seconds with nothing more than the CP post window in front of me.

    Ship it!

    Matt Gerrans

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #41

    Done! I rewrote it in Plain Portugese, though. Brazil is such an ignored market!

    Dave Kreskowiak Microsoft MVP - Visual Basic

    1 Reply Last reply
    0
    • N Nemanja Trifunovic

      Tomas Petricek wrote:

      My F# solution

      That's OCaml, right? Can't you use pattern matching?


      Programming Blog utf8-cpp

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #42

      Yes - see my Haskell solution :cool:

      1 Reply Last reply
      0
      • R Rama Krishna Vavilala

        I recently encountered/solved this problem and it is fairly simple. Column names in a database are named using Pascal casing, however to display it in a user friendly manner words need to be separated with spaces to generate display names. Following examples show the output for some strings.

        Name Display Name
        BodyHTML -> Body HTML
        LastAccessedTime -> Last Accessed Time
        ESOP -> ESOP

        In a language of your choice implement a procedure that will convert the column names to display names.

        String DisplayNameFromColumnName(String columnName) {
        }

        -- modified at 16:56 Friday 1st December, 2006 Removed XMLValue -> XML Value


        Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #43

        As usual - a Haskell solution. I decided to use raw list processing rather than regexes, 'cause I couldn't be bothered to look up the regex library functions... It also handles single letter wored like A - try "ThereIsAColumn"

        wordise [] = []
        wordise [x] = [x]
        wordise (x:y:rest)
           | (isAlpha x) && (isUpper y) = x: (' ': (wordise (y:rest)))
           | otherwise = x: (wordise (y:rest))
        

        -- modified at 19:53 Saturday 2nd December, 2006 OK - so I could be bothered to look up the regex functions...

        wordise2 s
           | Just (before, _, after, [lower, upper]) <- matchRegexAll (mkRegex "([a-zA-Z])([A-Z])") s 
                    = before ++ lower ++ (' ':upper) ++ (wordise after)
           | otherwise = s
        

        This uses a Haskell 98 extension called pattern guards to do pattern matching on the results of a function called on the input, rather than directly on the input. The first guard succeeds in the case of a successful regex match. The second handles a failing regex match by just returning the string.

        1 Reply Last reply
        0
        • T Tomas Petricek

          Yeah, F# is based on OCaml :). As I'm thinking about the problem it could be possible to use another very interesting F# feature called active patterns[^], but I have not played with this feature very much and I'm to lazy to think about it now.. it's friday :-O

          Tomas Petricek, C# MVP
          Tomasp.net | My Photos | My Blog (C# 3, LINQ, F# etc..)

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #44

          Active patterns look similar to a Haskell extension called pattern guards[^]. My Haskell solution has an example of their use...

          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