Solved

I want to Help vb convert to c# code

Posted on 2007-11-16
6
513 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

13 Experts available now in Live!

Get 1:1 Help Now