Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Replace and Remove from html string not working



  • I'm receiving html from a QJsonObject, but am having trouble formatting it well enough to be able to parse it.

    The html is quite long, so here's the beginning:

    <div class=\"iconset_wrapper\">\r\n 
    

    The html is located in jsonArray[6] which I then use .toString() on.

    I'd like to be able to parse it, but because of the escaped double quotes and the \r\n, I am unable to. I have confirmed that removing both problems allow my html to be parsed. To try and fix the problem, I came out with this:

    QString newHtml = jsonArray[6].toString().replace("\\\"", "\"").remove("\\r\\n");
    

    For some reason, however, the output is exactly the same (Have a print before and after).
    Is there something I'm missing? I'm doing the exact same thing a few lines above and it works just fine, what happened?


  • Moderators

    @RekTekk249 said in Replace and Remove from html string not working:

    For some reason, however, the output is exactly the same (Have a print before and after).

    replace() and remove() are working fine. Notice that your \r\n have disappeared.

    Are you printing through qDebug()? By default, qDebug() wraps strings with quotation marks ("). So if the string contains " characters, they will be escaped and printed as \".

    To view your actual text, display it in a QLabel or use qDebug().noquote() << newHtml;


  • Banned

    This post is deleted!

  • Moderators

    This post is deleted!


  • @JKSH Oh wow, you're completely right. I didn't know qDebug() behaved like this, I assumed noquote() was the default. Thanks for the help, I don't know how long it would have taken me to find out.


Log in to reply