encode characters

I am searching an encoder for VB, that encode characters (like java script escape function).

Does anyone have it?
LVL 1
sivanpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vbyuvalCommented:
I can build encoder with more than one encode format for you .
You will get it hour after I will see some pts !
0
autCommented:
Here's the URLEncode function:
'-----------------------
Public Function URLEncode(sDecoded As String) As String
    'This function URL-encodes a string
    '
    Dim Ascii As Byte, Char As String * 1
    Dim i As Integer
    Dim sOutput As String
    Dim TwoHex As String
   
    ' Change all spaces to pluses, and escape
    ' anything not A-Z or a-z
   
    For i = 1 To Len(sDecoded)
        Char = Mid(sDecoded, i, 1)
        Ascii = Asc(Char)
        If Ascii = 32 Then
            sOutput = sOutput + "+"
        ElseIf (Ascii < 65 Or Ascii > 122) And (Ascii < 48 Or Ascii > 57) Then
            TwoHex = Hex$(Ascii)
            If Len(TwoHex) = 1 Then TwoHex = "0" + TwoHex
            sOutput = sOutput + "%" + TwoHex
        Else
            sOutput = sOutput + Char
        End If
    Next i
   
    ' return encoded string to caller
    URLEncode = sOutput
End Function
'-----------------------




And the URLDecode function:
'-----------------------
Public Function URLDecode(sEncoded As String) As String
    'This function decodes a URL-encoded string
    Dim x As Integer, i As Integer
   
    'Check if the string is empty
    If sEncoded = "" Then Exit Function

   
    ' first fix all the plus signs
    Do
        x = InStr(x + 1, sEncoded, "+")
        If x = 0 Then Exit Do
        Mid(sEncoded, x, 1) = " "
    Loop
       
    ' now fix the %xx escapes
    On Error GoTo errorUrlDecode
    Do
        x = InStr(x + 1, sEncoded, "%")
        If x = 0 Then Exit Do
        i = Val("&H" + Mid(sEncoded, x + 1, 2))
        If i Then sEncoded = Left(sEncoded, x - 1) + Chr$(i) + Mid(sEncoded, x + 3)
    Loop
    URLDecode = sEncoded
Exit Function

errorUrlDecode:
    '--------------------------------------------------------------------
    ' If this function was mistakenly called with the following:
    '    UrlDecode("100% natural")
    ' a type mismatch error would be raised when trying to convert
    ' the 2 characters after "%" from hex to character.
    ' Instead, a more descriptive error message will be generated.
    '--------------------------------------------------------------------
    If Err.Number = 13 Then      'Type Mismatch error
        Err.Clear
        Err.Raise 65001, , "Invalid data passed to UrlDecode() function."
    Else
        Err.Raise Err.Number
    End If
    Resume Next
End Function
'-----------------------
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sivanpAuthor Commented:
Thanx a lot.
Thats exactly what I searched for.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.