Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I want to Help vb convert to c# code

Posted on 2007-11-16
6
Medium Priority
?
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 8

Accepted Solution

by:
Thejaka earned 1600 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 1600 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 1600 total points
ID: 20296889
Sorry, right first time!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Assisted Solution

by:nisarkhan
nisarkhan earned 400 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 1600 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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