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?
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:
' url encodes a string
Function URLEncode(ByVal str As String) As String
Dim intLen As Integer
Dim X As Integer
Dim curChar As Long
Dim newStr As String
intLen = Len(str)
newStr = ""
' encode anything which is not a letter or number
For X = 1 To intLen
curChar = Asc(Mid$(str, X, 1))
If curChar = 32 Then
' we can use a + sign for a space
newStr = newStr & "+"
ElseIf (curChar < 48 Or curChar > 57) And _
(curChar < 65 Or curChar > 90) And _
(curChar < 97 Or curChar > 122) Then
newStr = newStr & "%" & Hex(curChar)
Else
newStr = newStr & Chr(curChar)
End If
Next X
URLEncode = newStr
End Function
That doesn't encode everything, beause not all characters need to be encoded. What is it you need it for?
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.
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.