Created
November 1, 2022 14:13
-
-
Save misabitencourt/d6ff42c1a604b28a44842a7fe049042e to your computer and use it in GitHub Desktop.
Remove special characters from String on C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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