DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: case sensitive comparison

  1. #1
    Join Date
    Apr 2011
    Posts
    13

    case sensitive comparison

    Hello all

    I wanted to know if case sensitive comparison is possible between characters, not strings? Could anyone please tell me how do I go about it.

    Thanks

  2. #2
    Join Date
    Dec 2007
    Posts
    401
    Convert the chars to the same case and then compare them.

    The pedantically correct way of doing this:
    Code:
    #include <locale>
    
    void compare( char a, char b, const std::locale& loc = std::locale() )
    {
        char A = std::toupper( a, loc ), B = std::toupper( b, loc ) ;
        typedef std::char_traits<char> traits ;
        std::cout << a << "==" << b << "? " << std::boolalpha << traits::eq(A,B) << '\n'
                  << a << '<' << b << "? " << std::boolalpha << traits::lt(A,B) << '\n' ;
    }

  3. #3
    Join Date
    Apr 2011
    Posts
    13
    alright thank you vijayan

  4. #4
    Join Date
    Dec 2003
    Posts
    3,366
    thats case insensitive ... a == A using that. By default (you dont have to do anything) c++ says that 'A' != 'a' because it really treats char (and wide char) as integers which have different numeric values for 'a' and 'A'.

  5. #5
    Join Date
    Apr 2011
    Posts
    13
    Thanks jonnin for your reply :)

Similar Threads

  1. Accessing Icons in the Image Folder
    By rrjii2000 in forum .NET
    Replies: 35
    Last Post: 09-08-2010, 01:02 PM
  2. Databind Dropdown Asp.net
    By geo039 in forum ASP.NET
    Replies: 3
    Last Post: 08-06-2007, 03:46 PM
  3. errors with some varibles
    By ELHEK in forum Java
    Replies: 1
    Last Post: 10-01-2006, 05:08 PM
  4. Run-time error by a blank record made by code
    By VanDam in forum Database
    Replies: 0
    Last Post: 07-09-2005, 04:18 AM
  5. ADOX problem
    By Yoel Martinez in forum VB Classic
    Replies: 1
    Last Post: 12-12-2000, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center