Using QString I can remove any character from string, but what would be QRegExp to remove ALL non alphanumeric characters from that string. Currently I have written a function that will remove each character one by one, but I would like to know if i can do the same thing only in one step.
Here is my function
{
str.remove("\"");
str.remove("\\");
str.remove(".");
str.remove(",");
str.remove("?");
str.remove("!");
str.remove("'");
str.remove("`");
str.remove("-");
str.remove("_");
str.remove("—");
str.remove("@");
str.remove("#");
str.remove("$");
str.remove("%");
str.remove("^");
str.remove("&");
str.remove("*");
str.remove("(");
str.remove(")");
str.remove("{");
str.remove("}");
str.remove("[");
str.remove("]");
str.remove("|");
str.remove(";");
str.remove(":");
str.remove("/");
str.remove(">");
str.remove("<");
str.remove("~");
str.remove("=");
str.remove("+");
str.remove(str.fromUtf8("«"));
str.remove(str.fromUtf8("»"));
str = str.trimmed();
return str;
}
QString clean(QString str)
{
str.remove("\"");
str.remove("\\");
str.remove(".");
str.remove(",");
str.remove("?");
str.remove("!");
str.remove("'");
str.remove("`");
str.remove("-");
str.remove("_");
str.remove("—");
str.remove("@");
str.remove("#");
str.remove("$");
str.remove("%");
str.remove("^");
str.remove("&");
str.remove("*");
str.remove("(");
str.remove(")");
str.remove("{");
str.remove("}");
str.remove("[");
str.remove("]");
str.remove("|");
str.remove(";");
str.remove(":");
str.remove("/");
str.remove(">");
str.remove("<");
str.remove("~");
str.remove("=");
str.remove("+");
str.remove(str.fromUtf8("«"));
str.remove(str.fromUtf8("»"));
str = str.trimmed();
return str;
}
To copy to clipboard, switch view to plain text mode
Bookmarks