Results 1 to 5 of 5

Thread: Remove \n from QString

  1. #1

    Default Remove \n from QString

    Hi

    I have a string with 3 lines.

    "ABC"
    "ABC"
    "ABC"

    I want to remove second line.
    I can remove all characters in the line but still the line there is.

    "ABC"
    ""
    "ABC"

    I know in second line there is "\n"

    I tried to use remove("\n") but It does not work.

    So I need help with the problem.

    Regards
    Artur

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Remove \n from QString

    I would use QString::split("\n") to created a QStringList of all of the lines. Then you can keep/omit any specific line number or based on QString contents, etc.

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

    Default Re: Remove \n from QString

    You can remove the blank line by replacing a sequence of two newlines with one newline, see QString::replace().
    You could have a look at QString::section() also.

  4. #4

    Default Re: Remove \n from QString

    Hi

    Thank you for help.

    Today I found Why I have a lot of problems with my QString
    for example: The QStringList was not created well qDebug show only piece of QString.

    so The problem is that in one line of QString there is NULL char ( \0).
    but It is very hard to remove it How to remove it (I tried remve method but without success)

    Regards
    Artur

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

    Default Re: Remove \n from QString

    Does
    Qt Code:
    1. QString result = value.remove(QChar('\0'));
    2. //or
    3. QString result = value.remove(QChar(QChar::Null));
    To copy to clipboard, switch view to plain text mode 
    Work?

Similar Threads

  1. QString.remove() Why not working?
    By Noob in forum Newbie
    Replies: 3
    Last Post: 6th May 2013, 19:04
  2. How to remove whitespace in qstring in beginning?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 20th August 2012, 09:16
  3. Replies: 2
    Last Post: 11th August 2011, 16:42
  4. Replies: 3
    Last Post: 21st January 2011, 20:40
  5. Replies: 4
    Last Post: 31st January 2008, 21:44

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.