Solved

I want to Help vb convert to c# code

Posted on 2007-11-16
6
516 Views
Last Modified: 2008-02-01
Public Function URLEncode(PlainText As String) As String
Dim pLen
pLen = Len(PlainText)
        Dim HexPart As String
        Dim z As Long
        Dim OK As Boolean
        Dim i As Long
        Dim rtags() As String
        Dim recognised As String
        recognised = "*,+,-,.,0,1,2,3,4,5,6,7,8,9,_," & "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z," & "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
        rtags = Split(recognised, ",")
        Dim Ptags() As String
        ReDim Ptags(pLen)
        For i = 1 To Len(PlainText)
            Ptags(i) = Mid(PlainText, i, 1)
            OK = False
            For z = 0 To UBound(rtags)
                If Ptags(i) = rtags(z) Then
                    OK = True: Exit For
                End If
            Next
            If Not OK Then
                HexPart = Hex(Asc(Ptags(i)))
                If Len(HexPart) = 1 Then HexPart = "0" + HexPart
                Ptags(i) = "%" + HexPart
            End If
        Next
        URLEncode = Join(Ptags, "")
    End Function
0
Comment
Question by:sitg
  • 4
6 Comments
 
LVL 8

Accepted Solution

by:
Thejaka earned 400 total points
ID: 20296878

public string URLEncode(string PlainText) 
{ 
    object pLen; 
    pLen = Strings.Len(PlainText); 
    string HexPart; 
    long z; 
    bool OK; 
    long i; 
    string[] rtags; 
    string recognised; 
    recognised = "*,+,-,.,0,1,2,3,4,5,6,7,8,9,_," + "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z," + "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"; 
    rtags = Strings.Split(recognised, ","); 
    string[] Ptags;
    System.Array.Resize<string>(ref Ptags, pLen);
    for (i = 1; i <= Strings.Len(PlainText); i++) { 
        Ptags(i) = Strings.Mid(PlainText, i, 1); 
        OK = false; 
        for (z = 0; z <= Information.UBound(rtags); z++) { 
            if (Ptags(i) == rtags(z)) { 
                OK = true; 
                break;
            } 
        } 
        if (!OK) { 
            HexPart = Conversion.Hex(Strings.Asc(Ptags(i))); 
            if (Strings.Len(HexPart) == 1) 
                HexPart = "0" + HexPart; 
            Ptags(i) = "%" + HexPart; 
        } 
    } 
    return Strings.Join(Ptags, ""); 
}

Open in new window

0
 
LVL 8

Assisted Solution

by:Thejaka
Thejaka earned 400 total points
ID: 20296884
Oops! Correction:

Ptags = System.Array.Resize<string>(ref Ptags, pLen);

Open in new window

0
 
LVL 8

Assisted Solution

by:Thejaka
Thejaka earned 400 total points
ID: 20296889
Sorry, right first time!
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Assisted Solution

by:nisarkhan
nisarkhan earned 100 total points
ID: 20302981

public string URLEncode(string PlainText)
{
      object pLen;
      pLen = Len(PlainText);
      string HexPart;
      long z;
      bool OK;
      long i;
      string[] rtags;
      string recognised;
      recognised = "*,+,-,.,0,1,2,3,4,5,6,7,8,9,_," + "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z," + "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
      rtags = Split(recognised, ",");
      string[] Ptags;
       // ERROR: Not supported in C#: ReDimStatement

      for (i = 1; i <= Len(PlainText); i++) {
            Ptags(i) = Mid(PlainText, i, 1);
            OK = false;
            for (z = 0; z <= UBound(rtags); z++) {
                  if (Ptags(i) == rtags(z))
                  {
                        OK = true;
                        break; // TODO: might not be correct. Was : Exit For
                  }
            }
            if (!OK)
            {
                  HexPart = Hex(Asc(Ptags(i)));
                  if (Len(HexPart) == 1) HexPart = "0" + HexPart;
                  Ptags(i) = "%" + HexPart;
            }
      }
      URLEncode = Join(Ptags, "");
}


 
0
 
LVL 8

Assisted Solution

by:Thejaka
Thejaka earned 400 total points
ID: 20304006
To: nisarkhan

Your code has the following error:

// ERROR: Not supported in C#: ReDimStatement


You should use the following statement or similar instead:

System.Array.Resize<string>(ref Ptags, pLen);

Open in new window

0
 

Author Comment

by:sitg
ID: 20310376
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 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