?
Solved

I want to Help vb convert to c# code

Posted on 2007-11-16
6
Medium Priority
?
520 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
Independent Software Vendors: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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 …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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