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 to Integer

CString to Integer

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 4 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?

    C J D 3 Replies Last reply
    0
    • A Anonymous

      I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      Anonymous wrote: Or is there anyway to limit user to only type in integers? edit controls have a "number only" property. check for it in the resource editor / property viewre. Image Toolkits | Image Processing | Cleek

      1 Reply Last reply
      0
      • A Anonymous

        I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?

        J Offline
        J Offline
        Joel Holdsworth
        wrote on last edited by
        #3

        One good way to parse your strings is to use _stscanf like so:

        int a;
        CString mytext = _T("123Hello");
        if(_stscanf(mytext, _T("%d"), &a) != 1)
        {
        // An error happened
        }

        // a now contains the number if parsed correctly

        Joel Holdsworth Wanna give me a job this summer? Check out my online CV and project history[^]

        1 Reply Last reply
        0
        • A Anonymous

          I use checker = atoi( (LPCTSTR)str) to convert CString to int and checker to check if the number typed in CEdit box is within valid range. Now the problem is when user type a number then follow by letters. 1234abcd would return checker as 1234. How would I go about checking for non-integer characters? Or is there anyway to limit user to only type in integers?

          D Offline
          D Offline
          deldeep
          wrote on last edited by
          #4

          U can use _ttoi() . keep smilling.....b'coz smile is the shortest distance between people....

          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