Results 1 to 4 of 4

Thread: Split string

  1. #1
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Split string

    How can I split QString by numbers of characters ?
    Example:

    I've got QString with 1000 characters and I want to split it to QStringList or QList<QString> by 200 chars per line?

  2. #2
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Split string

    how about using remove(0,200) and adding this to a QStringList in a loop?
    Or you could insert a separator every 200 chars and then call QString::split on that.

  3. #3
    Join Date
    Sep 2009
    Location
    Warsaw/Poland
    Posts
    56
    Thanks
    8
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Split string

    but what if QString will be 983 length ? It won't fit to 200.. That's why I need good, fast and easy way to split it...

  4. #4
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Split string

    dude come on...
    your question was:
    I've got QString with 1000 characters and I want to split it to QStringList or QList<QString> by 200 chars per line?
    shouldn't be too hard to make it work for all cases but I'm not gonna write the code for you.

    btw Qt Documentation for QString::remove() mentions:
    If the specified position index is within the string, but position + n is beyond the end of the string, the string is truncated at the specified position.
    Last edited by schnitzel; 19th March 2011 at 19:27. Reason: updated contents

Similar Threads

  1. Replies: 7
    Last Post: 6th February 2017, 19:10
  2. split camel case string
    By GrahamLabdon in forum Newbie
    Replies: 5
    Last Post: 1st February 2011, 16:37
  3. How to split a string line
    By grsandeep85 in forum Newbie
    Replies: 5
    Last Post: 29th July 2009, 10:42
  4. How to split a string line
    By grsandeep85 in forum Qt Programming
    Replies: 2
    Last Post: 29th July 2009, 10:28
  5. how to split a class ?
    By mimmo_kallon in forum Newbie
    Replies: 0
    Last Post: 8th April 2008, 11:37

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.