Example 1: Case-Insensitive String Comparison
Explanation: This example uses the strcasecmp
function to perform a case-insensitive string comparison. It converts both strings to lowercase and then compares them.
Example 2: Remove Duplicates from a Case-Insensitive String
#include <iostream>
#include <algorithm>
#include <string>
int main() {
std::string input = “aABBbCCcd”;
std::sort(input.begin(), input.end());
auto last = std::unique(input.begin(), input.end());
input.erase(last, input.end());
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
std::cout << “Case-insensitive unique characters: ” << input << std::endl;
return 0;
}
std::sort
and std::unique
to remove duplicate characters from the string in a case-insensitive manner. The result is then transformed to lowercase using std::transform
.