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. if ( yousaid.GetAt(current_pos) == "[A-Z]" )

if ( yousaid.GetAt(current_pos) == "[A-Z]" )

Scheduled Pinned Locked Moved C / C++ / MFC
c++perltoolshelptutorial
3 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.
  • T Offline
    T Offline
    Tryhard
    wrote on last edited by
    #1

    Hi all, I apologise if this is real simple stuff, I am new to C++. I come from a 16 yr UNIX background, so I think in script & Perl. I am trying to check if a character in a CString is a uppercase Alpha. if ( yousaid.GetAt(current_pos) == "[A-Z]" ) This obviously isn't how to do it in C++ Any help appreciated. Cheers Dudes:confused: Tryhard :-)

    C M 2 Replies Last reply
    0
    • T Tryhard

      Hi all, I apologise if this is real simple stuff, I am new to C++. I come from a 16 yr UNIX background, so I think in script & Perl. I am trying to check if a character in a CString is a uppercase Alpha. if ( yousaid.GetAt(current_pos) == "[A-Z]" ) This obviously isn't how to do it in C++ Any help appreciated. Cheers Dudes:confused: Tryhard :-)

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

      The function isalpha will tell you if a character is a letter, the other way is to get a char out, like this:

      CString s("dsASdFDftSaSdAaasDdR");
      char a = s[0]; // Use the index to get out the char, you can use s.GetLength() to iterate over them
      if (a >= 'A' && a <= 'Z') // char automatically cats to int, which is why this works nicely.
      {
      AfxMessageBox("Uppercase");
      }

      If you wanted to test a whole string you could do this:

      CString s("dsASdFDftSaSdAaasDdR");
      CString d(s);
      d.MakeUpper();

      if (s==d)
      AfxMessageBox("All Upper");

      I'm sure someone else will suggest more intelligent ways of doing it, but those are the ways that spring to mind if you're using CString. If you were using basic_string you could do cool iterator stuff, but that is another story ( and CString is more useful than basic_string overall ). Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.

      1 Reply Last reply
      0
      • T Tryhard

        Hi all, I apologise if this is real simple stuff, I am new to C++. I come from a 16 yr UNIX background, so I think in script & Perl. I am trying to check if a character in a CString is a uppercase Alpha. if ( yousaid.GetAt(current_pos) == "[A-Z]" ) This obviously isn't how to do it in C++ Any help appreciated. Cheers Dudes:confused: Tryhard :-)

        M Offline
        M Offline
        markkuk
        wrote on last edited by
        #3

        if(_istupper(yousaid.GetAt(current_pos))is the correct, characterset and locale independent way to do it in VC++.

        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