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. General Programming
  3. C / C++ / MFC
  4. Empty String Overkill

Empty String Overkill

Scheduled Pinned Locked Moved C / C++ / MFC
6 Posts 6 Posters 0 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.
  • B Offline
    B Offline
    Blake Miller
    wrote on last edited by
    #1

    Is it just me, or does this seem like overkill to detect an empty string... if( strcmp( szPossiblyEmptyString, "" ) == 0 ) :doh: No shirt, no shoes, no brains, no service.

    G T D V 4 Replies Last reply
    0
    • B Blake Miller

      Is it just me, or does this seem like overkill to detect an empty string... if( strcmp( szPossiblyEmptyString, "" ) == 0 ) :doh: No shirt, no shoes, no brains, no service.

      G Offline
      G Offline
      grigsoft
      wrote on last edited by
      #2

      Yes, I usually do if (!(*szPossiblyEmptyString) ) But this maybe not very readable. Igor Green http://www.grigsoft.com/ - files and folders comparison tools

      1 Reply Last reply
      0
      • B Blake Miller

        Is it just me, or does this seem like overkill to detect an empty string... if( strcmp( szPossiblyEmptyString, "" ) == 0 ) :doh: No shirt, no shoes, no brains, no service.

        T Offline
        T Offline
        Tim Smith
        wrote on last edited by
        #3

        if (szPossiblyEmptyString [0] == 0) That works fine for testing for an empty string. If you also want to test for a NULL pointer if (pszString == NULL || pszString [0] == 0) Tim Smith I'm going to patent thought. I have yet to see any prior art.

        J 1 Reply Last reply
        0
        • T Tim Smith

          if (szPossiblyEmptyString [0] == 0) That works fine for testing for an empty string. If you also want to test for a NULL pointer if (pszString == NULL || pszString [0] == 0) Tim Smith I'm going to patent thought. I have yet to see any prior art.

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #4

          Tim Smith wrote:

          if (pszString == NULL || pszString [0] == 0)

          That's a good habit, in case one has to work with BSTR strings.
          -- Pictures[^] from my Japan trip.

          1 Reply Last reply
          0
          • B Blake Miller

            Is it just me, or does this seem like overkill to detect an empty string... if( strcmp( szPossiblyEmptyString, "" ) == 0 ) :doh: No shirt, no shoes, no brains, no service.

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Definitely superfluous. ;)


            "Take only what you need and leave the land as you found it." - Native American Proverb

            1 Reply Last reply
            0
            • B Blake Miller

              Is it just me, or does this seem like overkill to detect an empty string... if( strcmp( szPossiblyEmptyString, "" ) == 0 ) :doh: No shirt, no shoes, no brains, no service.

              V Offline
              V Offline
              VikramDelhi i
              wrote on last edited by
              #6

              Good Habit to inculcate.:-D

              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