Results 1 to 4 of 4

Thread: Replace text with full ASCII code?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Replace text with full ASCII code?

    does anyone have that code that will replace everything in data.txt with it's ASCII code? or a function that will do it? Something like this:

    Private Function ASCII(data As String) As String
    data = Replace(data, ">", "%3E")
    data = Replace(data, "`", "%60")
    data = Replace(data, "{", "%7B")
    data = Replace(data, "|", "%7C")
    data = Replace(data, "}", "%7D")
    data = Replace(data, "~", "%7E")
    data = Replace(data, ":", "%3A")
    data = Replace(data, ";", "%3B")
    data = Replace(data, "<", "%3C")
    data = Replace(data, "=", "%3D")
    data = Replace(data, Chr(34), "%22")
    PostASCII = data
    End Function

    I dont think i can find all the ascii. does anyone have it done already?

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Replace text with full ASCII code?

    The numbers you see there are ascii codes, but they are in hexecimal form. The %XX is URL encoding. I have function for this in the HTTP POST/GET program in my sig:
    VB Code:
    1. ' url encodes a string
    2. Function URLEncode(ByVal str As String) As String
    3.         Dim intLen As Integer
    4.         Dim X As Integer
    5.         Dim curChar As Long
    6.         Dim newStr As String
    7.                
    8.         intLen = Len(str)
    9.         newStr = ""
    10.        
    11.         ' encode anything which is not a letter or number
    12.         For X = 1 To intLen
    13.             curChar = Asc(Mid$(str, X, 1))
    14.            
    15.            
    16.             If curChar = 32 Then
    17.                 ' we can use a + sign for a space
    18.                 newStr = newStr & "+"
    19.             ElseIf (curChar < 48 Or curChar > 57) And _
    20.                 (curChar < 65 Or curChar > 90) And _
    21.                 (curChar < 97 Or curChar > 122) Then
    22.                
    23.                
    24.                 newStr = newStr & "%" & Hex(curChar)
    25.             Else
    26.                 newStr = newStr & Chr(curChar)
    27.             End If
    28.         Next X
    29.        
    30.         URLEncode = newStr
    31. End Function
    That doesn't encode everything, beause not all characters need to be encoded. What is it you need it for?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2004
    Posts
    294

    Re: Replace text with full ASCII code?

    I need it for winsock, when i used a packet sniffer everything was in ASCII (
    the data is really large). So what i wanted to do was have normal text then encode that text to ASCII, then send it using winsock.

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Replace text with full ASCII code?

    When you send a character via winsock, it is sent as ASCII, a string is after all a sequence of ASCII values. If the connection you were looking at was an HTTP connection, some data will be URL Encoded, the reasonfor this is to prevent data like spaces and commas from being interpretted as something else.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width