comparing strings

This is a discussion on comparing strings within the C++ Programming forums, part of the General Programming Boards category; I want to compare 2 strings. Is there a method to compare strings that is not case sensitive? Java has ...

  1. #1
    infinitum
    Guest

    comparing strings

    I want to compare 2 strings. Is there a method to compare strings that is not case sensitive? Java has one but I don't know about c++. I'm using .compare( "xxxx" ) and its case sensitive. I also just tried to convert all my strings to lowecase using strlwr( a ) where a: String a="some string" but I get an error saying the function doesnt take a string. I'm using MS Visual C++

    thanks,
    xer

  2. #2
    Registered User slaveofthenet's Avatar
    Join Date
    Apr 2003
    Posts
    80
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    string str1, str2;
    str1 = "ABC";
    str2 = "abc";
    if (!strcmpi(str1.c_str(), str2.c_str()))
         cout << "Strings are the same.";
    else
         cout << "Strings are different.";
    return 0;
    strcmpi() is a non case sensitive string comparison function which returns 0 if the strings are the same, negative if str1 is lesser than str2, and positive if str1 is greater than str2.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. comparing 2 strings with pointer
    By meriororen in forum C Programming
    Replies: 9
    Last Post: 05-22-2009, 07:37 PM
  2. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  3. Problem with comparing strings!
    By adrian2009 in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 09:44 PM
  4. comparing strings using argv
    By eth0 in forum C Programming
    Replies: 2
    Last Post: 09-20-2005, 09:20 AM
  5. Comparing Strings
    By Perica in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2003, 10:41 PM

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