Thread: How to compare 2 CString

  1. #1
    Unregistered
    Guest

    How to compare 2 CString

    I want to know
    How to compare 2 CString?
    is there something like strcmp(s1, s2)?

    Thanks

  2. #2
    Unregistered
    Guest
    I get it
    s1 == s2

    so simple

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    CString objects support comparison through the == operator as well as the Compare and CompareNoCase member functions (which return 0 if the strings are equal).

    Code:
    // example for CString == Operators
    CString s1( "abc" );
    CString s2( "abc" );
    if( s1 == s2 )
        cout << "They are the same." << endl;
    else
        cout << "They are different." << endl;
    Code:
    // example for CString::Compare
    CString s1( "abc" );
    CString s2( "abc" );
    if( !s1.Compare( s2 ) )
        cout << "They are the same." << endl;
    else
        cout << "They are different." << endl;
    Code:
    // example for CString::CompareNoCase
    CString s1( "abc" );
    CString s2( "ABC" );
    if( !s1.CompareNoCase( s2 ) )
        cout << "They are the same." << endl;
    else
        cout << "They are different." << endl;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. Writing CObjects with Serialization to CArchive
    By ruben_gerad in forum C++ Programming
    Replies: 0
    Last Post: 11-09-2006, 08:25 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Help with CString class and operator+ overloading
    By skanxalot in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2003, 10:23 AM
  5. How to compare CString and CArray?
    By ooosawaddee3 in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2002, 11:51 AM