VOOZH about

URL: https://www.geeksforgeeks.org/cpp/case-insensitive-string-comparison-in-cpp/

⇱ Case-Insensitive String Comparison in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Case-Insensitive String Comparison in C++

Last Updated : 23 Jul, 2025

In C++, strings are sequences of characters that are used to store text data which can be in both uppercase and lowercase format. In this article, we will learn how we can compare two case-insensitive strings in C++.

Example:

Input: 
string1 = "WELCOME TO GEEKS FOR GEEKS"
string2 = "welcome to geeks for geeks"

Output:
Strings are equal

Case-Insensitive String Comparison in C++

To compare two case-insensitive strings in C++, we have to temporarily convert both strings to either lowercase or uppercase. After that, we can compare them to get the result which will not depend upon the case of the characters.

Approach

  • Check if the lengths of both the strings are equal or not. If not return false.
  • Iterate through each character of both strings.
  • Convert each character to lowercase format using std::tolower method.
  • If any character is different return false.
  • If all characters were same return true.

C++ Program for Case-Insensitive String Comparison

The following program illustrates how we can compare two case-insensitive strings in C++:


Output
Strings are equal

Time complexity: O(N), where N denotes the length of the two strings.
Auxiliary Space: O(1)



Comment