Solved

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

Posted on 2007-11-15
3
332 Views
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;
            Stream.Close();
        }
        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;
    }
     
0
Comment
Question by:sitg
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 250 total points
ID: 20296542
The code above is in c#... do you have a problem with your code or do you want it in vb.net ?

Vb.net 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() 

        '.ReadText; 

        Stream.Close() 

    Else 

        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

0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 250 total points
ID: 20296549
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

0
 

Author Comment

by:sitg
ID: 20310382
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 33
Please explain "Multi-Tenant Services" 5 64
Tool Box 2 35
C# Offline Apllication 5 55
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

16 Experts available now in Live!

Get 1:1 Help Now