How to compare 2 CString

This is a discussion on How to compare 2 CString within the C++ Programming forums, part of the General Programming Boards category; I want to know How to compare 2 CString? is there something like strcmp(s1, s2)? Thanks...

  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,672
    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;
    I used to be an adventurer like you... then I took an arrow to the knee.

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, 07: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21