Results 1 to 3 of 3

Thread: Need support in removing the Carriage Returns

  1. #1
    Join Date
    Jan 2015
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Need support in removing the Carriage Returns

    Hello All
    As part of json response, I am getting a QString with multiple carriage returns.
    I need support in removing them , as the string is of quite a big size.
    I tried using
    Qt Code:
    1. QString::simplified
    2. QString::remove(QRegExp(["\r\n]));
    To copy to clipboard, switch view to plain text mode 
    Please find the string attached as a file.
    Attached Files Attached Files
    Last edited by kaml.mish; 28th March 2015 at 04:42. Reason: updated contents

  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: Need support in removing the Carriage Returns

    QString::siimplified() should work, it should leave you with one newline everywhere. If you want to remove all newlines then use QString::remove() passing '\n' as the frst argument. However I don't understand why you'd want to remove those new lines.
    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
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Need support in removing the Carriage Returns

    If you use the QJsonDocument, QJsonArray, and QJsonObject classes, it should simplify your parsing of the JSON data. If you need to store the JSON response in a compact format, the QJsonDocument::toJson() method has an argument that determines whether the resulting string is QJsonDocument::Indented (formatted with line breaks and indenting) or QJsonDocument::Compact (no formatting or line beaks).

    Disregard if you're using an old version of Qt that doesn't have the QJson* classes, but if possible, these will simplify your life!

Similar Threads

  1. insertPlainText and carriage return
    By RenanBS in forum Newbie
    Replies: 3
    Last Post: 28th August 2012, 18:41
  2. Carriage Return in QString
    By incapacitant in forum Newbie
    Replies: 7
    Last Post: 2nd December 2010, 09:18
  3. Having trouble with carriage return
    By FoleyX90 in forum Newbie
    Replies: 0
    Last Post: 27th May 2010, 16:15
  4. removing carriage return from QString
    By gren15 in forum Qt Programming
    Replies: 3
    Last Post: 28th June 2009, 22:07

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.