Results 1 to 4 of 4

Thread: QString sth between trimmed and simplified

  1. #1
    Join Date
    Aug 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default QString sth between trimmed and simplified

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString sth between trimmed and simplified

    This should work:
    Qt Code:
    1. QString str = "abc d e f ";
    2. str = str.replace(QRegExp("[ ]{2,}", " "));
    3. str.remove(QRegExp("^[ ]+"));
    4. str.remove(QRegExp("[ ]+$"));
    To copy to clipboard, switch view to plain text mode 

    An alternative is to encode special characters as some entities, then do simplifying and then decode the entities back.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString sth between trimmed and simplified

    Yeah...
    I was thinking that there is any method beside regular expressions
    but thanks for recipe

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QString sth between trimmed and simplified

    I'm pretty sure simplified() and trimmed() use regexps as well
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.