URL string query
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: URL string query

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,235

    URL string query

    I'm trying to debug a function which decodes URL strings. For example the string file:///C:/some%20filename would get changed to file:///C:/some filename

    As expected, the function has replaced "%20" with a space character. For reasons I don't understand though, the function also removes '+' characters from the URL - so file:///C:/some+filename also gets changed to file:///C:/some filename (with the '+' character getting replaced by a space). Would this be normal behaviour for a URL decoder? I didn't think that '+' was special or illegal in any way.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  2. #2
    Join Date
    Sep 2011
    Posts
    13

    Re: URL string query

    hi John

    try this function i made

    Code:
    void STRING_Replace( string &Text, string Key, string Value )
    {
    	// don't allow any infinite loops
    
    	if( Value.find( Key ) != string :: npos )
    		return;
    
    	string :: size_type KeyStart = Text.find( Key );
    
    	while( KeyStart != string :: npos )
    	{
    		Text.replace( KeyStart, Key.size( ), Value );
    		KeyStart = Text.find( Key );
    	}
    }
    best regards
    Jacob

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,235

    Re: URL string query

    Thanks for the suggestion Jacob. To be honest I'm happy enough with the provided code - except for being confused about why it filters out '+' characters and replaces with space characters. I know that certain characters are special in URLs (such as '%') but AFAIK the '+' character is just a normal character, like 'a', 'b' or 'c'. Unless somebody knows different...
    "A problem well stated is a problem half solved. - Charles F. Kettering

  4. #4
    Join Date
    Jan 2009
    Posts
    596

    Re: URL string query

    The + sign is another way to encode spaces in urls. It is normally used in query strings - you can see this by typing a few words into google and seeing the url it creates for the results page.

    If a + sign is actually needed in a url it can be, but must be encoded, as %2B.

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,235

    Re: URL string query

    Ah, it's making sense now. Thanks Peter.
    "A problem well stated is a problem half solved. - Charles F. Kettering

  6. #6
    Join Date
    Jan 2009
    Posts
    1,689

    Re: URL string query

    curl_unescape is what you want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center