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#
  4. How to convert a char from IO stream into an int please

How to convert a char from IO stream into an int please

Scheduled Pinned Locked Moved C#
tutorial
4 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.
  • H Offline
    H Offline
    humblepgmr
    wrote on last edited by
    #1

    Hi all, I'm having some trouble getting with this: char temp = System.Console.ReadKey(); //Throws an exception So I tried System.Console.ReadKey().KeyChar which returns the ascii value of the key I entered... Basically I need to get a key that falls in the range of 0-10 There's a validation line that handles if temp > 0 || temp < 10... but I can't get the character to convert into an int properly. Thanks Humble

    P 1 Reply Last reply
    0
    • H humblepgmr

      Hi all, I'm having some trouble getting with this: char temp = System.Console.ReadKey(); //Throws an exception So I tried System.Console.ReadKey().KeyChar which returns the ascii value of the key I entered... Basically I need to get a key that falls in the range of 0-10 There's a validation line that handles if temp > 0 || temp < 10... but I can't get the character to convert into an int properly. Thanks Humble

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2
      if (Char.IsNumeric(Readkey().KeyChar))
      

      should tell you if it's a number of not.

      Deja View - the feeling that you've seen this post before.

      H 1 Reply Last reply
      0
      • P Pete OHanlon
        if (Char.IsNumeric(Readkey().KeyChar))
        

        should tell you if it's a number of not.

        Deja View - the feeling that you've seen this post before.

        H Offline
        H Offline
        humblepgmr
        wrote on last edited by
        #3

        Yeah, I've got the validation portion down... I need to get the character, which if entered proprly is an integer number, and convert it into an integer for processing.

        M 1 Reply Last reply
        0
        • H humblepgmr

          Yeah, I've got the validation portion down... I need to get the character, which if entered proprly is an integer number, and convert it into an integer for processing.

          M Offline
          M Offline
          Matthew Cuba
          wrote on last edited by
          #4

          Probably an easier way but this seems to work: int val = Convert.ToInt32(e.KeyChar.ToString()); Good Luck!

          “You can't teach people to be lazy - either they have it, or they don't.” -Dagwood Bumbstead

          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