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

Replace and Remove from html string not working

Scheduled Pinned Locked Moved Solved General and Desktop
qstringhtmljson
5 Posts 3 Posters 975 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 18 Mar 2021, 01:05 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?

    J 1 Reply Last reply 18 Mar 2021, 02:17
    0
    • R RekTekk249
      18 Mar 2021, 01:05

      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?

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 18 Mar 2021, 02:17 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 18 Mar 2021, 15:42
      5
      • R Offline
        R Offline
        Royal13m
        Banned
        wrote on 18 Mar 2021, 08:04 last edited by
        #3
        This post is deleted!
        J 1 Reply Last reply 18 Mar 2021, 08:20
        0
        • R Royal13m
          18 Mar 2021, 08:04

          This post is deleted!

          J Offline
          J Offline
          JKSH
          Moderators
          wrote on 18 Mar 2021, 08:20 last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • J JKSH
            18 Mar 2021, 02:17

            @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 18 Mar 2021, 15:42 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

            1/5

            18 Mar 2021, 01:05

            • Login

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