Solved

I want to Help vb convert to c# code

Posted on 2007-11-16
6
515 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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