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 check if a character is from keyboard in MFC

How to check if a character is from keyboard in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
6 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
    Andraw111
    wrote on last edited by
    #1

    Hi, dear all, I need to read a component's description from a libary. but sometimes there are some garbage values at the end of descrtion string tail, I want to remove them. So after get the description, I want to check character one by one, if the character is not a character input from keyboard, I will remove them. But how can I do it? thanks!

    E S 2 Replies Last reply
    0
    • A Andraw111

      Hi, dear all, I need to read a component's description from a libary. but sometimes there are some garbage values at the end of descrtion string tail, I want to remove them. So after get the description, I want to check character one by one, if the character is not a character input from keyboard, I will remove them. But how can I do it? thanks!

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #2

      Andraw111 wrote:

      but sometimes there are some garbage values at the end of descrtion string tail, I want to remove them.

      - What type of the string is used ? - Is the garbage offset allways the same ? - Does the get-methode return the length of its answer as well ? :)

      They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

      1 Reply Last reply
      0
      • A Andraw111

        Hi, dear all, I need to read a component's description from a libary. but sometimes there are some garbage values at the end of descrtion string tail, I want to remove them. So after get the description, I want to check character one by one, if the character is not a character input from keyboard, I will remove them. But how can I do it? thanks!

        S Offline
        S Offline
        Software_Developer
        wrote on last edited by
        #3

        [isalnum() ] does the job.

        P 1 Reply Last reply
        0
        • S Software_Developer

          [isalnum() ] does the job.

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          Probably not. I think a "description" of an item would include some punctuation and spaces. Peter

          Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

          S 1 Reply Last reply
          0
          • P Peter_in_2780

            Probably not. I think a "description" of an item would include some punctuation and spaces. Peter

            Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

            S Offline
            S Offline
            Software_Developer
            wrote on last edited by
            #5

            Then is_from_keyboard() below is better suited. It includes punctuation , spaces etc.

            #include
            using namespace std;

            int is_from_keyboard(int ch)
            {

            if ( ch>31 && ch<128) return 1;
            else return -1;
            

            }

            int main()
            {
            char ch='z';

            if (is_from_keyboard(ch))

               cout<<"The ASCII character  -> "< "<
            
            E 1 Reply Last reply
            0
            • S Software_Developer

              Then is_from_keyboard() below is better suited. It includes punctuation , spaces etc.

              #include
              using namespace std;

              int is_from_keyboard(int ch)
              {

              if ( ch>31 && ch<128) return 1;
              else return -1;
              

              }

              int main()
              {
              char ch='z';

              if (is_from_keyboard(ch))

                 cout<<"The ASCII character  -> "< "<
              
              E Offline
              E Offline
              Eugen Podsypalnikov
              wrote on last edited by
              #6

              void aChinaGarbageTest()
              {
              ASSERT(31 < _TCHAR('武') && _TCHAR('武') < 128);
              }

              They sought it with thimbles, they sought it with care; They pursued it with forks and hope; They threatened its life with a railway-share; They charmed it with smiles and soap. :)

              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