PDA

View Full Version : QString sth between trimmed and simplified



pmlody
2nd November 2009, 22:29
Hi all
I need method to trim from begin, end and all internal spaces ( like trimmed + internal ) but leave special characters ( like \n or \t ) just unlike simplified.

wysota
3rd November 2009, 00:05
This should work:

QString str = "abc d e f ";
str = str.replace(QRegExp("[ ]{2,}", " "));
str.remove(QRegExp("^[ ]+"));
str.remove(QRegExp("[ ]+$"));

An alternative is to encode special characters as some entities, then do simplifying and then decode the entities back.

pmlody
3rd November 2009, 07:06
Yeah...
I was thinking that there is any method beside regular expressions :)
but thanks for recipe :)

wysota
3rd November 2009, 09:13
I'm pretty sure simplified() and trimmed() use regexps as well :)