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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. atoi?

atoi?

Scheduled Pinned Locked Moved C#
c++questioncsharp
5 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.
  • D Offline
    D Offline
    dec82
    wrote on last edited by
    #1

    what is the C# equivalent of "atoi" in Visual C++? thanks

    B L 2 Replies Last reply
    0
    • D dec82

      what is the C# equivalent of "atoi" in Visual C++? thanks

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      PAsk the questions in Right forum.Put in C++ forum.

      Cheers!! Brij

      1 Reply Last reply
      0
      • D dec82

        what is the C# equivalent of "atoi" in Visual C++? thanks

        L Offline
        L Offline
        Luis Alonso Ramos
        wrote on last edited by
        #3

        int.Parse or Convert.ToInt32. They will throw an exception if the string cannot be converted. int.TryParse won't throw an exception, and should be used if the string possible could not be valid.

        Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

        A 1 Reply Last reply
        0
        • L Luis Alonso Ramos

          int.Parse or Convert.ToInt32. They will throw an exception if the string cannot be converted. int.TryParse won't throw an exception, and should be used if the string possible could not be valid.

          Luis Alonso Ramos Intelectix Chihuahua, Mexico My Blog!

          A Offline
          A Offline
          AORD
          wrote on last edited by
          #4

          But what if you have a string like "us dollars $34cheap". TryParse gives 0 for the result. atoi would give 34. Is there anything in C# that does exactly what atoi does in C++?

          L 1 Reply Last reply
          0
          • A AORD

            But what if you have a string like "us dollars $34cheap". TryParse gives 0 for the result. atoi would give 34. Is there anything in C# that does exactly what atoi does in C++?

            L Offline
            L Offline
            Luis Alonso Ramos
            wrote on last edited by
            #5

            I don't know of anyting, but it wouldn't be hard to implement it yourself. Just walk all the characters in the string, and copy the ones that are numbers to a temporal string, ignoring letters and symbols. Then int.TryParse that temporal string and you're done.

            Luis Alonso Ramos Intelectix Chihuahua, Mexico Follow me on Twitter (@luisalonsoramos) or on my blog (www.luisalonsoramos.com)!

            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