Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to create an equivalent to JavaScript encodeURIComponent and decodeURIComponent in VB.NET

1 Answer

0 votes
Imports System
Imports System.Web

Public Class Program
    Public Shared Function DecodeURIComponent(ByVal s As String) As String
        If s Is Nothing Then
            Return Nothing
        End If

        Dim result As String

        Try
            result = HttpUtility.UrlDecode(s)
        Catch __unusedException1__ As Exception
            result = s
        End Try

        Return result
    End Function

    Public Shared Function EncodeURIComponent(ByVal str As String) As String
        Dim result As String

        Try
            result = HttpUtility.UrlEncode(str).
						Replace("+", "%20").
						Replace("%21", "!").
						Replace("%27", "'").
						Replace("%28", "(").
						Replace("%29", ")").
						Replace("%7E", "~")
        Catch __unusedException1__ As Exception
            result = str
        End Try

        Return result
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim str As String = "https://www.seek4info.com/search.php?query=seo"
		
        Dim encode As String = EncodeURIComponent(str)
        Console.WriteLine(encode)
		
        Dim decode As String = DecodeURIComponent(encode)
        Console.WriteLine(decode)
    End Sub
End Class



' run:
'
' https%3a%2f%2fwww.seek4info.com%2fsearch.php%3fquery%3dseo
' https://www.seek4info.com/search.php?query=seo
'

 



answered Apr 13, 2025 by avibootz
...