Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Replace and Remove from html string not working
QtWS25 Last Chance

Replace and Remove from html string not working

Scheduled Pinned Locked Moved Solved General and Desktop
qstringhtmljson
5 Posts 3 Posters 974 Views
  • 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 Offline
    R Offline
    RekTekk249
    wrote on last edited by
    #1

    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?

    JKSHJ 1 Reply Last reply
    0
    • R RekTekk249

      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?

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by JKSH
      #2

      @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
      5
      • R Offline
        R Offline
        Royal13m
        Banned
        wrote on last edited by
        #3
        This post is deleted!
        JKSHJ 1 Reply Last reply
        0
        • R Royal13m

          This post is deleted!

          JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • JKSHJ 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 Offline
            R Offline
            RekTekk249
            wrote on last edited by
            #5

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

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved