Thread: piece of code: Decode urls in c++

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    Post piece of code: Decode urls in c++

    Code:
    std::string urlDecode(std::string &eString) {   
      std::string ret;    
      char ch;    int i, j;    
      for (i=0; i<eString.length(); i++) {        
         if (int(eString[i])==37) {           
              sscanf(eString.substr(i+1,2).c_str(), "%x", &j);            
              ch=static_cast<char>(j);            
               ret+=ch;            
               i=i+2;        
          } else {           
               ret+=eString[i];        
          }    
       }   
     return (ret);
    }
    Decode URLs in C++

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Do you have a question, or are you seeking comments on your code?
    Or is this just "hey, visit my site"?

    > if (int(eString[i])==37)
    How about replacing 37 with '%'

    > sscanf(eString.substr(i+1,2).c_str(), "%x", &j);
    How about looking up what stringstreams can do for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Optimalise a piece of code
    By thescratchy in forum C Programming
    Replies: 10
    Last Post: 09-02-2010, 11:41 AM
  2. help me to decode this code
    By -EquinoX- in forum C Programming
    Replies: 13
    Last Post: 02-08-2008, 11:55 AM
  3. Help with a piece of code
    By Victor4015 in forum C++ Programming
    Replies: 1
    Last Post: 11-16-2005, 05:38 PM
  4. Help with a little piece of code
    By cdonlan in forum C Programming
    Replies: 5
    Last Post: 11-15-2004, 12:38 PM
  5. question about a piece of code
    By librab103 in forum C Programming
    Replies: 6
    Last Post: 06-27-2003, 01:11 PM