I have a problem I want to convert vb code to c# code

Posted on 2007-11-15
Last Modified: 2008-02-01
public object URLDecode(string What)
        object functionReturnValue = null;
        int Pos;
        int pPos;
        What = What.ToString().Replace("+", " ");
        StringReader Stream = new StringReader(What);
        ErrorEventArgs Err;
        if (Convert.ToInt64(Err) == 0) {
            Pos = What.ToString().IndexOf("%",1);
            pPos = 1;
            while (Pos > 0) {
               pPos = Pos + 3;
               Pos = What.ToString().IndexOf("%", pPos);
            Stream.WriteText(Strings.Mid(What, pPos));
            Stream.Position = 0;
            functionReturnValue = Stream.ReadToEnd();//.ReadText;
        else {
            Pos = What.ToString().IndexOf("%", 1);
            while (Pos > 0) {
               What = Strings.Left(What, Pos - 1) + Strings.Chr((long)"&H" + Strings.Mid(What, Pos + 1, 2)) + Strings.Mid(What, Pos + 3);
                Pos = Pos + 1;
                Pos = What.ToString().IndexOf("%", Pos);
            functionReturnValue = What;
        Stream = null;
        return functionReturnValue;
Question by:sitg
LVL 53

Accepted Solution

Dhaest earned 250 total points
Comment Utility
The code above is in c#... do you have a problem with your code or do you want it in ? code of example above
Public Function URLDecode(ByVal What As String) As Object 

    Dim functionReturnValue As Object = Nothing 

    Dim Pos As Integer 

    Dim pPos As Integer 

    What = What.ToString().Replace("+", " ") 

    Dim Stream As New StringReader(What) 

    Dim Err As ErrorEventArgs 

    If Convert.ToInt64(Err) = 0 Then 

        Pos = What.ToString().IndexOf("%", 1) 

        pPos = 1 

        While Pos > 0 

            pPos = Pos + 3 

            Pos = What.ToString().IndexOf("%", pPos) 

        End While 

        Stream.WriteText(Strings.Mid(What, pPos)) 

        Stream.Position = 0 

        functionReturnValue = Stream.ReadToEnd() 




        Pos = What.ToString().IndexOf("%", 1) 

        While Pos > 0 

            What = Strings.Left(What, Pos - 1) + Strings.Chr(CLng("&H") + Strings.Mid(What, Pos + 1, 2)) + Strings.Mid(What, Pos + 3) 

            Pos = Pos + 1 

            Pos = What.ToString().IndexOf("%", Pos) 

        End While 

        functionReturnValue = What 

    End If 

    Stream = Nothing 

    Return functionReturnValue 

End Function 

Open in new window

LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 250 total points
Comment Utility
You don't have to do all this. There is a ready-made .net function for this:
public string URLDecode(string What)


       return System.Web.HttpUtility.UrlDecode(What);


Open in new window


Author Comment

Comment Utility

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now