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. CString quandry

CString quandry

Scheduled Pinned Locked Moved C / C++ / MFC
comquestion
5 Posts 3 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.
  • C Offline
    C Offline
    carrie
    wrote on last edited by
    #1

    I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)

    L A 3 Replies Last reply
    0
    • C carrie

      I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      bool is_chardigit(const CString& str, int index) { // check if CString is long enough first return isdigit(string.GetAt(index)); } My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

      C 1 Reply Last reply
      0
      • L Lost User

        bool is_chardigit(const CString& str, int index) { // check if CString is long enough first return isdigit(string.GetAt(index)); } My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

        C Offline
        C Offline
        carrie
        wrote on last edited by
        #3

        fantastic, I knew there was something I was missing but I just couldn't see it. Thanks for the great fast help :)

        1 Reply Last reply
        0
        • C carrie

          I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          One more thing. I did not read your question completely. There is a better solution. You can do this

          bool check_if_dotted_ip(const char* str)
          {
          return (inet_addr(str) != INADDR_NONE);
          }

          My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

          1 Reply Last reply
          0
          • C carrie

            I was wondering, pondering even, what would be the easiest way to check 1 character in a CString to see if it was a number? The scenario is I have a string that could either be www.blah.com or it could be 123.123.123.132 or some other domain name or IP. I want to check whether its a domain name or IP address before I process the details, but I can't decide on the easiest way to do it. Would a nasty if (string.GetAt(0}=='1')||(string.GetAt(0)=='2'....... be the easiest way or is there some other technique I've not noticed? Cheers lads & lassies :)

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            maybe something along the line of IsNumeric(string.GetAt(0)) ? I am not sure of output of string.GetAt(0), there fore assuming that you are extracting the first character from the string. hope this helps

            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