Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Percent-decoding a URL

Percent-decoding a URL

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
13 Posts 9 Posters 0 Views 1 Watching
  • 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.
  • C ClementsDan

    Shortly before my co-worker left for vacation today, he wrote something like this:

    strNew.Replace("%20", " ");
    strNew.Replace("%21", "!");
    strNew.Replace("%22", """);
    strNew.Replace("%23", "#");
    strNew.Replace("%24", "$");
    strNew.Replace("%25", "%");
    strNew.Replace("%26", "&");
    strNew.Replace("%27", "'");
    strNew.Replace("%28", "(");
    strNew.Replace("%29", ")");
    strNew.Replace("%2A", "*");
    strNew.Replace("%2B", "+");
    strNew.Replace("%2C", ",");
    strNew.Replace("%2D", "-");
    strNew.Replace("%2E", ".");
    strNew.Replace("%2F", "/");
    strNew.Replace("%2a", "*");
    strNew.Replace("%2b", "+");
    strNew.Replace("%2c", ",");
    strNew.Replace("%2d", "-");
    strNew.Replace("%2e", ".");
    strNew.Replace("%2f", "/");
    strNew.Replace("%3A", ":");
    strNew.Replace("%3B", ";");
    strNew.Replace("%3C", "<");
    strNew.Replace("%3D", "=");
    strNew.Replace("%3E", ">");
    strNew.Replace("%3F", "?");
    strNew.Replace("%3a", ":");
    strNew.Replace("%3b", ";");
    strNew.Replace("%3c", "<");
    strNew.Replace("%3d", "=");
    strNew.Replace("%3e", ">");
    strNew.Replace("%3f", "?");
    strNew.Replace("%40", "@");
    strNew.Replace("%5B", "[");
    strNew.Replace("%5C", "\\");
    strNew.Replace("%5D", "]");
    strNew.Replace("%5E", "^");
    strNew.Replace("%5F", "_");
    strNew.Replace("%5b", "[");
    strNew.Replace("%5c", "\\");
    strNew.Replace("%5d", "]");
    strNew.Replace("%5e", "^");
    strNew.Replace("%5f", "_");
    strNew.Replace("%60", "`");
    strNew.Replace("%7B", "{");
    strNew.Replace("%7C", "|");
    strNew.Replace("%7D", "}");
    strNew.Replace("%7E", "~");
    strNew.Replace("%7b", "{");
    strNew.Replace("%7c", "|");
    strNew.Replace("%7d", "}");
    strNew.Replace("%7e", "~");

    T Offline
    T Offline
    Tony Pottier
    wrote on last edited by
    #4

    Your coworker is a genius. strNew.Replace("%7E", "~"); ... strNew.Replace("%7e", "~"); This one adds another wtf to the thing. You should probably send to to the dailywtf.com.

    1 Reply Last reply
    0
    • C ClementsDan

      Shortly before my co-worker left for vacation today, he wrote something like this:

      strNew.Replace("%20", " ");
      strNew.Replace("%21", "!");
      strNew.Replace("%22", """);
      strNew.Replace("%23", "#");
      strNew.Replace("%24", "$");
      strNew.Replace("%25", "%");
      strNew.Replace("%26", "&");
      strNew.Replace("%27", "'");
      strNew.Replace("%28", "(");
      strNew.Replace("%29", ")");
      strNew.Replace("%2A", "*");
      strNew.Replace("%2B", "+");
      strNew.Replace("%2C", ",");
      strNew.Replace("%2D", "-");
      strNew.Replace("%2E", ".");
      strNew.Replace("%2F", "/");
      strNew.Replace("%2a", "*");
      strNew.Replace("%2b", "+");
      strNew.Replace("%2c", ",");
      strNew.Replace("%2d", "-");
      strNew.Replace("%2e", ".");
      strNew.Replace("%2f", "/");
      strNew.Replace("%3A", ":");
      strNew.Replace("%3B", ";");
      strNew.Replace("%3C", "<");
      strNew.Replace("%3D", "=");
      strNew.Replace("%3E", ">");
      strNew.Replace("%3F", "?");
      strNew.Replace("%3a", ":");
      strNew.Replace("%3b", ";");
      strNew.Replace("%3c", "<");
      strNew.Replace("%3d", "=");
      strNew.Replace("%3e", ">");
      strNew.Replace("%3f", "?");
      strNew.Replace("%40", "@");
      strNew.Replace("%5B", "[");
      strNew.Replace("%5C", "\\");
      strNew.Replace("%5D", "]");
      strNew.Replace("%5E", "^");
      strNew.Replace("%5F", "_");
      strNew.Replace("%5b", "[");
      strNew.Replace("%5c", "\\");
      strNew.Replace("%5d", "]");
      strNew.Replace("%5e", "^");
      strNew.Replace("%5f", "_");
      strNew.Replace("%60", "`");
      strNew.Replace("%7B", "{");
      strNew.Replace("%7C", "|");
      strNew.Replace("%7D", "}");
      strNew.Replace("%7E", "~");
      strNew.Replace("%7b", "{");
      strNew.Replace("%7c", "|");
      strNew.Replace("%7d", "}");
      strNew.Replace("%7e", "~");

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #5

      Apart from the fact that it's a horror code, it will just won't work as he needs to assign value returned by Replace to strnew strNew = strNew.Replace("%20", " ");

      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

      N S 2 Replies Last reply
      0
      • G Giorgi Dalakishvili

        Apart from the fact that it's a horror code, it will just won't work as he needs to assign value returned by Replace to strnew strNew = strNew.Replace("%20", " ");

        Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

        N Offline
        N Offline
        notmasteryet
        wrote on last edited by
        #6

        If the code was written on C++ strNew might be a CString, if it was written on C# it might be StringBuilder.

        C 1 Reply Last reply
        0
        • C ClementsDan

          Shortly before my co-worker left for vacation today, he wrote something like this:

          strNew.Replace("%20", " ");
          strNew.Replace("%21", "!");
          strNew.Replace("%22", """);
          strNew.Replace("%23", "#");
          strNew.Replace("%24", "$");
          strNew.Replace("%25", "%");
          strNew.Replace("%26", "&");
          strNew.Replace("%27", "'");
          strNew.Replace("%28", "(");
          strNew.Replace("%29", ")");
          strNew.Replace("%2A", "*");
          strNew.Replace("%2B", "+");
          strNew.Replace("%2C", ",");
          strNew.Replace("%2D", "-");
          strNew.Replace("%2E", ".");
          strNew.Replace("%2F", "/");
          strNew.Replace("%2a", "*");
          strNew.Replace("%2b", "+");
          strNew.Replace("%2c", ",");
          strNew.Replace("%2d", "-");
          strNew.Replace("%2e", ".");
          strNew.Replace("%2f", "/");
          strNew.Replace("%3A", ":");
          strNew.Replace("%3B", ";");
          strNew.Replace("%3C", "<");
          strNew.Replace("%3D", "=");
          strNew.Replace("%3E", ">");
          strNew.Replace("%3F", "?");
          strNew.Replace("%3a", ":");
          strNew.Replace("%3b", ";");
          strNew.Replace("%3c", "<");
          strNew.Replace("%3d", "=");
          strNew.Replace("%3e", ">");
          strNew.Replace("%3f", "?");
          strNew.Replace("%40", "@");
          strNew.Replace("%5B", "[");
          strNew.Replace("%5C", "\\");
          strNew.Replace("%5D", "]");
          strNew.Replace("%5E", "^");
          strNew.Replace("%5F", "_");
          strNew.Replace("%5b", "[");
          strNew.Replace("%5c", "\\");
          strNew.Replace("%5d", "]");
          strNew.Replace("%5e", "^");
          strNew.Replace("%5f", "_");
          strNew.Replace("%60", "`");
          strNew.Replace("%7B", "{");
          strNew.Replace("%7C", "|");
          strNew.Replace("%7D", "}");
          strNew.Replace("%7E", "~");
          strNew.Replace("%7b", "{");
          strNew.Replace("%7c", "|");
          strNew.Replace("%7d", "}");
          strNew.Replace("%7e", "~");

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #7

          any regex alternatives by your co-worker? that might be really interesting... :laugh:

          Luc Pattyn [Forum Guidelines] [My Articles]


          Fixturized forever. :confused:


          1 Reply Last reply
          0
          • C ClementsDan

            Shortly before my co-worker left for vacation today, he wrote something like this:

            strNew.Replace("%20", " ");
            strNew.Replace("%21", "!");
            strNew.Replace("%22", """);
            strNew.Replace("%23", "#");
            strNew.Replace("%24", "$");
            strNew.Replace("%25", "%");
            strNew.Replace("%26", "&");
            strNew.Replace("%27", "'");
            strNew.Replace("%28", "(");
            strNew.Replace("%29", ")");
            strNew.Replace("%2A", "*");
            strNew.Replace("%2B", "+");
            strNew.Replace("%2C", ",");
            strNew.Replace("%2D", "-");
            strNew.Replace("%2E", ".");
            strNew.Replace("%2F", "/");
            strNew.Replace("%2a", "*");
            strNew.Replace("%2b", "+");
            strNew.Replace("%2c", ",");
            strNew.Replace("%2d", "-");
            strNew.Replace("%2e", ".");
            strNew.Replace("%2f", "/");
            strNew.Replace("%3A", ":");
            strNew.Replace("%3B", ";");
            strNew.Replace("%3C", "<");
            strNew.Replace("%3D", "=");
            strNew.Replace("%3E", ">");
            strNew.Replace("%3F", "?");
            strNew.Replace("%3a", ":");
            strNew.Replace("%3b", ";");
            strNew.Replace("%3c", "<");
            strNew.Replace("%3d", "=");
            strNew.Replace("%3e", ">");
            strNew.Replace("%3f", "?");
            strNew.Replace("%40", "@");
            strNew.Replace("%5B", "[");
            strNew.Replace("%5C", "\\");
            strNew.Replace("%5D", "]");
            strNew.Replace("%5E", "^");
            strNew.Replace("%5F", "_");
            strNew.Replace("%5b", "[");
            strNew.Replace("%5c", "\\");
            strNew.Replace("%5d", "]");
            strNew.Replace("%5e", "^");
            strNew.Replace("%5f", "_");
            strNew.Replace("%60", "`");
            strNew.Replace("%7B", "{");
            strNew.Replace("%7C", "|");
            strNew.Replace("%7D", "}");
            strNew.Replace("%7E", "~");
            strNew.Replace("%7b", "{");
            strNew.Replace("%7c", "|");
            strNew.Replace("%7d", "}");
            strNew.Replace("%7e", "~");

            S Offline
            S Offline
            supercat9
            wrote on last edited by
            #8

            Assuming strNew is of a type that allows replace to be used upon it in that fashion, would its treatment of "%253F" match any known standard?

            C L 2 Replies Last reply
            0
            • S supercat9

              Assuming strNew is of a type that allows replace to be used upon it in that fashion, would its treatment of "%253F" match any known standard?

              C Offline
              C Offline
              ClementsDan
              wrote on last edited by
              #9

              "%253F" → "%3F" → "?". I don't know of any standard that encodes a question mark that way.

              1 Reply Last reply
              0
              • N notmasteryet

                If the code was written on C++ strNew might be a CString, if it was written on C# it might be StringBuilder.

                C Offline
                C Offline
                ClementsDan
                wrote on last edited by
                #10

                Right. It's a CString.

                1 Reply Last reply
                0
                • S supercat9

                  Assuming strNew is of a type that allows replace to be used upon it in that fashion, would its treatment of "%253F" match any known standard?

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #11

                  This minor mistake is easily fixed by moving the %25 -> % replacement to the bottom of the magnificent method. :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  Fixturized forever. :confused:


                  1 Reply Last reply
                  0
                  • C ClementsDan

                    Shortly before my co-worker left for vacation today, he wrote something like this:

                    strNew.Replace("%20", " ");
                    strNew.Replace("%21", "!");
                    strNew.Replace("%22", """);
                    strNew.Replace("%23", "#");
                    strNew.Replace("%24", "$");
                    strNew.Replace("%25", "%");
                    strNew.Replace("%26", "&");
                    strNew.Replace("%27", "'");
                    strNew.Replace("%28", "(");
                    strNew.Replace("%29", ")");
                    strNew.Replace("%2A", "*");
                    strNew.Replace("%2B", "+");
                    strNew.Replace("%2C", ",");
                    strNew.Replace("%2D", "-");
                    strNew.Replace("%2E", ".");
                    strNew.Replace("%2F", "/");
                    strNew.Replace("%2a", "*");
                    strNew.Replace("%2b", "+");
                    strNew.Replace("%2c", ",");
                    strNew.Replace("%2d", "-");
                    strNew.Replace("%2e", ".");
                    strNew.Replace("%2f", "/");
                    strNew.Replace("%3A", ":");
                    strNew.Replace("%3B", ";");
                    strNew.Replace("%3C", "<");
                    strNew.Replace("%3D", "=");
                    strNew.Replace("%3E", ">");
                    strNew.Replace("%3F", "?");
                    strNew.Replace("%3a", ":");
                    strNew.Replace("%3b", ";");
                    strNew.Replace("%3c", "<");
                    strNew.Replace("%3d", "=");
                    strNew.Replace("%3e", ">");
                    strNew.Replace("%3f", "?");
                    strNew.Replace("%40", "@");
                    strNew.Replace("%5B", "[");
                    strNew.Replace("%5C", "\\");
                    strNew.Replace("%5D", "]");
                    strNew.Replace("%5E", "^");
                    strNew.Replace("%5F", "_");
                    strNew.Replace("%5b", "[");
                    strNew.Replace("%5c", "\\");
                    strNew.Replace("%5d", "]");
                    strNew.Replace("%5e", "^");
                    strNew.Replace("%5f", "_");
                    strNew.Replace("%60", "`");
                    strNew.Replace("%7B", "{");
                    strNew.Replace("%7C", "|");
                    strNew.Replace("%7D", "}");
                    strNew.Replace("%7E", "~");
                    strNew.Replace("%7b", "{");
                    strNew.Replace("%7c", "|");
                    strNew.Replace("%7d", "}");
                    strNew.Replace("%7e", "~");

                    C Offline
                    C Offline
                    Chris Meech
                    wrote on last edited by
                    #12

                    Your co-worker definitely needs the vacation. Months of rest and medication may help them out. :)

                    Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

                    1 Reply Last reply
                    0
                    • G Giorgi Dalakishvili

                      Apart from the fact that it's a horror code, it will just won't work as he needs to assign value returned by Replace to strnew strNew = strNew.Replace("%20", " ");

                      Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion

                      S Offline
                      S Offline
                      StevenWalsh
                      wrote on last edited by
                      #13

                      not if its a StringBuilder

                      Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer. -Fred Brooks

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups