Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Replace and Remove from html string not working

    General and Desktop
    qstring html json
    3
    5
    306
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      RekTekk249 last edited by

      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?

      JKSH 1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators @RekTekk249 last edited by JKSH

        @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;

        R 1 Reply Last reply Reply Quote 5
        • R
          Royal13m Banned last edited by

          This post is deleted!
          JKSH 1 Reply Last reply Reply Quote 0
          • JKSH
            JKSH Moderators @Royal13m last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • R
              RekTekk249 @JKSH last edited by

              @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.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post