PDA

View Full Version : simplified alternative



wirasto
22nd October 2013, 19:40
There is a function like simplified (http://qt-project.org/doc/qt-4.8/qstring.html#simplified) but not trim start whitespaces?

toufic.dbouk
22nd October 2013, 21:15
Nothin that i am aware off but you can always try something.
Like just use the simplified function over the substring that doesn't contain the start-whitespaces. ( you can find several ways to get that substring )

Good Luck.

wysota
22nd October 2013, 21:50
There is a function like simplified (http://qt-project.org/doc/qt-4.8/qstring.html#simplified) but not trim start whitespaces?


QRegExp rx("(\\s*[^\\s]+)");
rx.match(string);
QString simplified = rx.cap(1);

ChrisW67
22nd October 2013, 22:59
That will give you the first "word" and any leading whitespace, but not subsequent words with whitespace runs collapsed to single spaces as simplified() does (if you use QRegularExpression::match() or QRegExp::indexIn()).

wysota
23rd October 2013, 08:07
True. However it should work if you allow multiples of such groups. Other than that a simple for loop iterating from the end of the string and chopping off whitespaces is a good approach.