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. how to convert valied strings into int?

how to convert valied strings into int?

Scheduled Pinned Locked Moved C / C++ / MFC
comtutorialquestion
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.
  • I Offline
    I Offline
    imran_rafique
    wrote on last edited by
    #1

    i am having string's like following examples in a loop ------------------- @123456 @65465498 @-65465498 123456k 65465498 k -65465498 l how are u nice dear -------------------- these are the strings that i want to convert them into integer value but they also contain characters and speces and sentances. how to convert valied strings into int? can any body tell the good check so that ? is there any way to neglect character in a string? r00d0034@yahoo.com

    C W 2 Replies Last reply
    0
    • I imran_rafique

      i am having string's like following examples in a loop ------------------- @123456 @65465498 @-65465498 123456k 65465498 k -65465498 l how are u nice dear -------------------- these are the strings that i want to convert them into integer value but they also contain characters and speces and sentances. how to convert valied strings into int? can any body tell the good check so that ? is there any way to neglect character in a string? r00d0034@yahoo.com

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Why are you asking this on the C++ forum, having found out how to do it in C# ? Is it a bad enough problem to change languages over ? In C++, you have some functions called ::isalpha and ::isalnum. If the first returns false and the second returns true, you have a number. These functions take a character, not a string. You need to use these functions to parse your strings, then use atoi on the strings that you've verified have only numbers, or built to have only numbers. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

      I 1 Reply Last reply
      0
      • I imran_rafique

        i am having string's like following examples in a loop ------------------- @123456 @65465498 @-65465498 123456k 65465498 k -65465498 l how are u nice dear -------------------- these are the strings that i want to convert them into integer value but they also contain characters and speces and sentances. how to convert valied strings into int? can any body tell the good check so that ? is there any way to neglect character in a string? r00d0034@yahoo.com

        W Offline
        W Offline
        wabc
        wrote on last edited by
        #3

        I am afraid that you have to write your own function,test the left side of your string,if it's not a integer or a "+" or "-",trim it off,and then use the function "atoi" to convert the remainder string to integer.

        1 Reply Last reply
        0
        • C Christian Graus

          Why are you asking this on the C++ forum, having found out how to do it in C# ? Is it a bad enough problem to change languages over ? In C++, you have some functions called ::isalpha and ::isalnum. If the first returns false and the second returns true, you have a number. These functions take a character, not a string. You need to use these functions to parse your strings, then use atoi on the strings that you've verified have only numbers, or built to have only numbers. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

          I Offline
          I Offline
          imran_rafique
          wrote on last edited by
          #4

          thanks a lot for your answer? i hope you have found your answer? r00d0034@yahoo.com

          C 1 Reply Last reply
          0
          • I imran_rafique

            thanks a lot for your answer? i hope you have found your answer? r00d0034@yahoo.com

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            imran_rafique wrote: thanks a lot for your answer? You're welcome. imran_rafique wrote: i hope you have found your answer? Yes, thanks. I asked a couple of questions a day or so ago, got some pointers, looked them up in the MSDN and all is well with me. Good luck with your project. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002 Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002 During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002

            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