Skip to content

Instantly share code, notes, and snippets.

@misabitencourt
Created November 1, 2022 14:13
Show Gist options
  • Save misabitencourt/d6ff42c1a604b28a44842a7fe049042e to your computer and use it in GitHub Desktop.
Save misabitencourt/d6ff42c1a604b28a44842a7fe049042e to your computer and use it in GitHub Desktop.
Remove special characters from String on C++
#include <iostream>
#include <string>
#include <bits/stdc++.h>
std::string normalizeString(const std::string &input)
{
std::string output = "";
std::string validChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZáãàâéêẽèíìîóôòõúù!@#$%^&*()_|+,.<>{}[]\\/-=?;:'\" \n";
std::string validUpper = "" + validChars;
transform(validUpper.begin(), validUpper.end(), validUpper.begin(), ::toupper);
std::string validLower = ""+validChars;
transform(validChars.begin(), validChars.end(), validChars.begin(), ::tolower);
for (int i=0; i<input.length(); i++) {
std::cout << input[i] << "\n";
if (validChars.find(input[i]) > validChars.length() &&
validLower.find(input[i]) > validChars.length() &&
validUpper.find(input[i]) > validUpper.length()) {
continue;
}
output += input[i];
}
return output;
}
int main() {
std::cout << normalizeString("Hello, world! └");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment