QString replace multiple characters in a single call?
-
wrote on 5 Aug 2020, 16:36 last edited by
I want to replace multiple characters in a QString, I can do this:
strContent.replace("\n", " "); strContent.replace("\r", " "); strContent.replace("\t", " ");
What I would like to do is something like this:
QStringList slstBytes; slstBytes << "\n" << "\r" << "\t"; strContent.replace(slstBytes, " ");
I know this isn't possible with the current build, that's just an example.
-
I want to replace multiple characters in a QString, I can do this:
strContent.replace("\n", " "); strContent.replace("\r", " "); strContent.replace("\t", " ");
What I would like to do is something like this:
QStringList slstBytes; slstBytes << "\n" << "\r" << "\t"; strContent.replace(slstBytes, " ");
I know this isn't possible with the current build, that's just an example.
strContent.replace(QRegularExpression("[\\n|\\r|\\t]+"), " ");
-
wrote on 5 Aug 2020, 16:48 last edited by
If it's just those non-printable chars like \n, \r and \t that you want replaced with space, you can use simplified():
strContent = strContent.simplified();
-
I want to replace multiple characters in a QString, I can do this:
strContent.replace("\n", " "); strContent.replace("\r", " "); strContent.replace("\t", " ");
What I would like to do is something like this:
QStringList slstBytes; slstBytes << "\n" << "\r" << "\t"; strContent.replace(slstBytes, " ");
I know this isn't possible with the current build, that's just an example.
strContent.replace(QRegularExpression("[\\n|\\r|\\t]+"), " ");
-
wrote on 5 Aug 2020, 16:50 last edited by
@raven-worx said in QString replace multiple characters in a single call?:
strContent.replace(QRegularExpression("[\n|\r|\t]+"), " ");
Thank you, thats exactly what I was looking for.
1/4