Results 1 to 5 of 5

Thread: QReqExp for any number of white spaces

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    48
    Thanked 2 Times in 2 Posts

    Default QReqExp for any number of white spaces

    Hello

    any body can help me with a ReqExp for any number of white spaces...

    I tried "[//s]" but this match one space. .

    I Have a qStringList f.e = " xxxxxx xxxxxx xxxxx xxx xx"

    I want to split each word by the spaces

    when i tried QSl.splite("")

    this give me a QStringList has each word but also has empty Strings.

    so how can i have a QStringList with onlyt the words. im tryin to use the white space regexp to split my qstringlist.

    thanks

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QReqExp for any number of white spaces

    Quote Originally Posted by jesse_mark View Post
    any body can help me with a ReqExp for any number of white spaces...
    I tried "[//s]" but this match one space. .
    The regular expression you given will match a single forward slash / or letter s. Did you mean "\\s" perhaps?
    I Have a qStringList f.e = " xxxxxx xxxxxx xxxxx xxx xx"
    You probably have a QString not a QStringList. A QStringList is what you will get when you split the string. If you do, indeed, have a QStringList then you need to split each string in the list separately.
    I want to split each word by the spaces
    when i tried QSl.splite("")
    Neither QStringList nor QString has a splite() function. Did you mean QString::split() perhaps? Did you also mean to put a space between the quotes?
    this give me a QStringList has each word but also has empty Strings.
    Yes, that is what you asked it for. QString::split() has more than one argument, and one of them is obviously useful in this situation.
    so how can i have a QStringList with onlyt the words. im tryin to use the white space regexp to split my qstringlist.
    You do not need a regular expression to do this but: "\\s+" will match one or more whitepaces.

  3. The following user says thank you to ChrisW67 for this useful post:

    jesse_mark (9th November 2012)

  4. #3
    Join Date
    Jun 2012
    Posts
    173
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    48
    Thanked 2 Times in 2 Posts

    Default Re: QReqExp for any number of white spaces

    Thanks you so much for taking time and replying to me with details helped me really.

    The regular expression you given will match a single forward slash / or letter s. Did you mean "\\s" perhaps?
    Yes, i did mean "\\s"

    You probably have a QString not a QStringList. A QStringList is what you will get when you split the string. If you do, indeed, have a QStringList then you need to split each string in the list separately.
    Yes, you are completely right, I do have QStringList and i need to split each string in the list separately .

    Neither QStringList nor QString has a splite() function. Did you mean QString::split() perhaps? Did you also mean to put a space between the quotes?
    I think QString does has the Spilt() function becuz this what i use... MyQstring.split("space") ..... yes i did put space between the quotes, but i don't know why the editor eats all the spaces.

    Yes, that is what you asked it for. QString::split() has more than one argument, and one of them is obviously useful in this situation.
    Yes this what i asked for, but i dont want it to keep the empty strings, but thank i looked again to the other arguments the split has and i there are three
    1 - the qstring or the reqexp
    2- Split behavior , which has a default value KeepEmptyParts .. << this what i need to change
    3: Case sensitivity which also has a default value Qt::CaseSensitive

    You do not need a regular expression to do this but: "\\s+" will match one or more whitepaces.
    I want to use the Qstring.split(QRegExp("\\s+")); to split the each word of the string and create a list.
    what other way can i use to do that with out using the regular expression ??

    Thank you again

  5. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: QReqExp for any number of white spaces

    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: QReqExp for any number of white spaces

    Quote Originally Posted by jesse_mark View Post
    2- Split behavior , which has a default value KeepEmptyParts .. << this what i need to change
    So change it.

    what other way can i use to do that with out using the regular expression ??
    See above

Similar Threads

  1. Replies: 1
    Last Post: 5th March 2012, 07:34
  2. A text widget that handles line wrapping of white spaces?
    By Thuan Seah Tan in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2011, 00:17
  3. Replies: 1
    Last Post: 15th January 2010, 21:11
  4. Spaces in QTextEdit
    By jgrauman in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2009, 19:28
  5. Spaces between lines in QTextEdit
    By troorl_ua in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 01:06

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
  •  
Qt is a trademark of The Qt Company.