|
-
Nov 9th, 2010, 11:10 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Convert VB Url Encode Method to C#
Hi guys, I have a method that encodes a Url. I want to convert it to C# normally I dont have a issue with things like this but it looks like it is calling itself without a value passed, very strange looking. Any tips on how to convert are much appreciated.
Code:
Function URLEncode(ByVal Text As String) As String
Dim i As Integer
Dim acode As Integer
'Dim char As String
URLEncode = Text
For i = Len(URLEncode) To 1 Step -1
acode = Asc(Mid$(URLEncode, i, 1))
Select Case acode
Case 48 To 57, 65 To 90, 97 To 122
' don't touch alphanumeric chars
Case 32
URLEncode = URLEncode.Substring(0, i - 1) & "+" & Mid(URLEncode, i + 1)
' replace space with "+"
Case Else
' replace punctuation chars with "%hex"
URLEncode = URLEncode.Substring(0, i - 1) & "%" & Hex$(acode) & Mid$(URLEncode, i + 1)
End Select
' End If
Next
If InStr(URLEncode, "%D%A") Then
URLEncode = Replace(URLEncode, "%D%A", "%0D%0A")
End If
End Function
-
Nov 9th, 2010, 11:49 AM
#2
Re: Convert VB Url Encode Method to C#
There's a built-in encode method already:
System.Web.HttpServerUtility.UrlEncode(Text);
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Nov 9th, 2010, 12:02 PM
#3
Thread Starter
Frenzied Member
Re: Convert VB Url Encode Method to C#
Not in the compact framework there is not, or at least it doesnt seem to be.
-
Nov 9th, 2010, 12:07 PM
#4
Thread Starter
Frenzied Member
Re: Convert VB Url Encode Method to C#
Seems they changed it round:
Code:
System.Net.HttpUtility.UrlEncode(MessageToSend);
-
Nov 9th, 2010, 12:23 PM
#5
Re: [RESOLVED] Convert VB Url Encode Method to C#
OK, these two should be though:
System.Uri.EscapeUriString(Text);
System.Uri.EscapeDataString(Text);
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Nov 9th, 2010, 12:24 PM
#6
Re: Convert VB Url Encode Method to C#
 Originally Posted by DeanMc
Seems they changed it round:
Code:
System.Net.HttpUtility.UrlEncode(MessageToSend);
Good find!
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Nov 9th, 2010, 12:38 PM
#7
Thread Starter
Frenzied Member
Re: [RESOLVED] Convert VB Url Encode Method to C#
Cheers, it was a passing comment of a different site, nearly missed it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|