Results 1 to 19 of 19

Thread: how to decode URI Component in vb6(removing %% from urls)?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    how to decode URI Component in vb6(removing %% from urls)?

    Hi all . I got urls as variable but they are in diffrent format like this:

    http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab

    I wonder how i can remove those % and make it like this?:
    http://w3schools.com/my test.asp?name=ståle&car=saab

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: how to decode URI Component in vb6(removing %% from urls)?

    I was playing with this
    Code:
    Option Explicit
    
    Private Function ConvertToString(ByVal strD As String) As String
    Dim strN As String
    Dim intPos As Integer
    Do
        intPos = InStr(strD, "%")
        If intPos > 0 Then
            strN = Chr(Val("&H" & Mid$(strD, intPos + 1, 2)))
            Mid$(strD, intPos, 1) = strN
            strD = Mid$(strD, 1, intPos) & Mid$(strD, intPos + 3, Len(strD) - (intPos + 1))
        End If
    Loop Until intPos <= 0
    ConvertToString = strD
    End Function
    
    Private Sub Command_Click()
    Dim strD As String
    strD = "http%3A%2F%2Fw3schools.com%2Fmy%20test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab"
    Debug.Print ConvertToString(strD)
    End Sub
    but couldn't see how to convert %C3%A5 into å (hex E3)

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Isn't there a reverse to URLEncode?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: how to decode URI Component in vb6(removing %% from urls)?

    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Quote Originally Posted by Doogle View Post
    but couldn't see how to convert %C3%A5 into å (hex E3)
    mainly because http://w3schools.com/my test.asp?name=ståle&car=saab actually encodes to http%3A%2F%2Fw3schools%2Ecom%2Fmy+test%2Easp%3Fname%3Dst%E5le%26car%3Dsaab

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    What you have there is a UTF-8 URL.

    These are common now, because the standard long ago changed from a mix of ASCII and whatever else people felt like doing. The mishmash that resulted plus the desire for full Unicode support led to the change. Remember, the Internet was never developed for general international use when first constructed, so year by year we get more patches on top of patches. Browsers are a mess inside, for this and many other reasons.

    There are some nice API calls in SHLWAPI.DLL for URL encoding and decoding. But until Windows 8 they do not handle UTF-8. They were built for the safe, 7-bit ASCII subset of ANSI and for UTF-16LE/UCS-2 (which VBers tend to think of as "Unicode" even though Unicode means many things).

    With a hack and a prayer you can combine the SHLWAPI calls with conversion API calls, and almost get it right most of the time. This isn't safe though (it fails on some characters), so you're back to some hand-rolled logic.


    The attached demo shows one way to reliably accomplish this. Of course that doesn't mean there aren't bugs there either since I threw it together quickly. Test it to find and fix lingering errors.

    Most (if not all?) of the links posted above were obsolete the day they were posted, so you can safely ignore them. People should really spend a few minutes to read 2003's famous exposition:

    The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dilettante; Oct 25th, 2012 at 01:49 AM.

  7. #7
    New Member
    Join Date
    Oct 2013
    Posts
    8

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Hi dilettante,

    Thank you for posting your very nice code. I tried it and it works great.

    However I am trying to solve the OPPOSITE problem. I need to encode the text from non-English language to format that Bing.com can understand. Let's take the word "фиттнесс" (means "fittness" in Russian). All encoders I found so far converts it into %F4%E8%F2%F2%ED%E5%F1%F1 . And it is wrong line because call to Bing like
    http://www.bing.com/search?q=%F4%E8%F2%F2%ED%E5%F1%F1
    returns NOTHING.

    The correct line for the word "фиттнесс" is %D1%84%D0%B8%D1%82%D1%82%D0%BD%D0%B5%D1%81%D1%81 .

    I tried to decode this word with your decoder and it worked great. However how I can encode this "фиттнесс" to "%D1%84%D0%B8%D1%82%D1%82%D0%BD%D0%B5%D1%81%D1%81" using VB6???

    There is online encoder on http://meyerweb.com/eric/tools/dencoder/ , but I need to repliate this functionality in VB6.

    I will greatly appreciate your help.

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    You could probably just reverse what the program above does, calling WideCharToMultiByte to go the opposite direction.

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Or, you could get the source code from that Web Site and use the Java Script in it. It's OK because they say you can copy the source code and save it to your hard drive.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Quote Originally Posted by jmsrickland View Post
    Or, you could get the source code from that Web Site and use the Java Script in it. It's OK because they say you can copy the source code and save it to your hard drive.
    Actually I took a look and they oversimplify the process by a ton (producing incorrect results), but then again I did much the same in my demo above as well. The problem is the %-ecoding of things like the "://" after after "http" in a URL.


    Here is an attempt to do it "properly"... well almost properly, see the comments in my UrlQueryStringEncode() function. But it should be good enough for what you need I hope. Again, see the comments if you need to perfect the process.

    There are a ton of rules for fiddling with URLs. The parts before a query have one set of rules and whatever comes as the querystring of a URL have whatever rules the target web site chose to use more or less.

    For this reason there aren't any simple API or object method calls that do entirely what you are asking for. So in this program I'm grabbing off the query part, encoding that (using a hack for pre-Win7 systems), and then glueing the two parts back together.


    You could also just rip out quite a few of the API calls and just use my "pre-Win7 hack" (i.e. Utf8Escape() function) by itself if you pass it a querystring that you want to convert to escaped UTF-8.


    Name:  sshot.png
Views: 2523
Size:  14.7 KB


    Warning:

    In order to allow the use of Unicode text, I am using the Microsoft InkEdit Control instead of a TextBox. This is already part of Windows Vista and later though, and there should still be an inkless version available for installation into WinXP and Win2K. Or you might substitute an MS Forms 2.0 TextBox here.
    Attached Files Attached Files
    Last edited by dilettante; Dec 11th, 2013 at 11:49 PM. Reason: Fixed ridiculous bug!

  11. #11
    New Member
    Join Date
    Oct 2013
    Posts
    8

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Hi dilettante,

    Thank you VERY MUCH for your excellent code. You actually solved more complex problem with extraction of query from URL search string. What I was needed - only convertsion of non-English words to esc format acceptable by Bing.com. Anyhow, your code works great and gets the job done. Is it OK for you if I will use your posted code in my application (free of charge )?

  12. #12
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Glad it is helpful.

    Sure, go ahead and use it. I made no license claims in the source so the only encumbrance is the implied Copyright. My understanding is that the way it was published here allows you to do anything you want with the code except (a.) claim that you are the original author, or (b.) anything that violates VBForums' Content Licensing terms.

  13. #13
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: how to decode URI Component in vb6(removing %% from urls)?

    @dilettante

    From your post #10 are you stating your app will not function on XP?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  14. #14
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    To run it under Windows XP you would have to have the Microsoft Ink controls installed (which do not ship in XP except for Windows XP Tablet PC Edition). You can get these as part of Microsoft Windows XP Tablet PC Edition Software Development Kit 1.7, or it is possible that some 3rd party application may have installed the InkEdit control on your system already.

    Or you could replace the upper "textbox" in the picture with an MS Forms 2.0 TextBox or some other Unicode textbox control. Or if you were running with Russian language locale settings a plain old ANSI VB6 intrinsic TextBox might be (?) good enough.

    In this case it is all about being able to enter the foreign language text (Russian here).
    Last edited by dilettante; Dec 12th, 2013 at 02:07 PM.

  15. #15
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    I just tested a clean XP SP 3 system, and sure enough:

    Component 'Inked.dll' or one of its dependencies not correctly registered: a file is missing or invalid

  16. #16
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    XP DeathClock


    Windows XP End Of Support Countdown Gadget

    Supported Operating System

    Windows 7, Windows Vista
    Windows 7 32-bit or 64-bit, any edition.

  17. #17
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Funny that on the first link they show you a count down timer for the end of support on XP and then over on the right they tell you to download SP3 and 4 Steps to Speed Up XP


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  18. #18
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: how to decode URI Component in vb6(removing %% from urls)?

    Maybe they don't quite believe it.

  19. #19
    Lively Member
    Join Date
    Apr 2013
    Posts
    91

    Re: how to decode URI Component in vb6(removing %% from urls)?

    how to decode unicode links like &hearts; &upsilon; &sigma;?? in vb6

Posting Permissions

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



Click Here to Expand Forum to Full Width