How to case insensitive remove specific character from a string in C++

1 Answer

0 votes
#include <iostream>
#include <algorithm>
#include <cctype>
 
void RemoveByCharCaseInsensitive(std::string &s, char ch) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    
    s.erase(std::remove(s.begin(), s.end(), tolower(ch)), s.end());
}
 
int main()
{
    std::string s = "C++ Programming";
 
    RemoveByCharCaseInsensitive(s, 'p');
 
    std::cout << s;
}
 
 
 
 
/*
run:
 
C++ rogramming
 
*/

 



answered Sep 27, 2022 by avibootz
...