[Qt-interest] Multiplied spaces by QRegExp

Julien Cugnière julien.cugniere at gmail.com
Fri Apr 16 18:29:26 CEST 2010


2010/4/16 M. Bashir Al-Noimi <mbnoimi at gmx.com>:
> I want to remove any multiplied spaces from specific string.
>
> For example:
>
> " This is   my  source"
>
> modified to:
>
> " This is my source"
>
> I tried to run this snippet but it didn't work! could you help me please?
>
> QString str = " This is   my  source";
> str.remove(QRegExp("[\" \"]+"));

Try this : str.replace(QRegExp(" +"), " ");

You could also use str.simplified(), but it doesn't keep spaces at the
beginning and end of the string, which doesn't seem to be what you
want.

-- 
Julien Cugnière




More information about the Qt-interest-old mailing list