|
-
Jan 14th, 2009, 03:52 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Replace chars
hi,
i was wondering where can i find or how it's called the reversion or changing chars to...i don't know how to call it...
This is what i did through an application that hepled me...
Text5.Text = pReplace(Text5.Text, "_", " ")
Text5.Text = pReplace(Text5.Text, ",", "%2C")
Text5.Text = pReplace(Text5.Text, "&", "%26")
Text5.Text = pReplace(Text5.Text, " ", "+")
Text5.Text = pReplace(Text5.Text, "(", "%28")
Text5.Text = pReplace(Text5.Text, ")", "%29")
So i replaced the standard chars with the "encoded" ones and i don't know how to get all those codes for other standard chars?
Any help?
Thanks for helping me out.
-
Jan 14th, 2009, 10:36 PM
#2
Re: Replace chars
you can use the str_replace() function to replace characters, and you can use a sheet like this to find ascii character codes.
-
Jan 15th, 2009, 02:33 AM
#3
Thread Starter
Hyperactive Member
Re: Replace chars
yeah bu ascii chars are not the ones that are used when you send data over POST method....and that's what i need
Ex.
you see how %2C = ,
Thanks for helping me out.
-
Jan 15th, 2009, 03:43 AM
#4
Re: Replace chars
uh.. you want to build a URL? then use url_encode(). that would only matter when using GET, not POST.
-
Jan 15th, 2009, 07:15 AM
#5
Thread Starter
Hyperactive Member
Re: Replace chars
What the url_encode()
Can you tell which functions is that???
I think that could solve alot of problems for me 
BTW im using that in Visual Basic ...
Last edited by batori; Jan 15th, 2009 at 07:35 AM.
Thanks for helping me out.
-
Jan 15th, 2009, 03:04 PM
#6
Re: Replace chars
you can look up every function using PHP.net. in this case, you can look here. I mistyped, and it was urlencode() without the underscore.
-
Jan 15th, 2009, 07:05 PM
#7
Thread Starter
Hyperactive Member
Re: Replace chars
Well i got the code..
For example, this string:
Some test (text) with wierd ;-) characters + more!
becomes this:
Some+test+%28text%29+with+wierd+%3B%2D%29+characters+%2B+more%21
' Return a URL safe encoding of txt.
Private Function URLEncode(ByVal txt As String) As String
Dim i As Integer
Dim ch As String
Dim ch_asc As Integer
Dim result As String
SetSafeChars
result = ""
For i = 1 To Len(txt)
' Translate the next character.
ch = Mid$(txt, i, 1)
ch_asc = Asc(ch)
If ch_asc = vbKeySpace Then
' Use a plus.
result = result & "+"
ElseIf m_SafeChar(ch_asc) Then
' Use the character.
result = result & ch
Else
' Convert the character to hex.
result = result & "%" & Right$("0" & _
Hex$(ch_asc), 2)
End If
Next i
URLEncode = result
End Function
Private m_SafeChar(0 To 255) As Boolean
' Set m_SafeChar(i) = True for characters that
' do not need protection.
Private Sub SetSafeChars()
Static done_before As Boolean
Dim i As Integer
If done_before Then Exit Sub
done_before = True
For i = 0 To 47
m_SafeChar(i) = False
Next i
For i = 48 To 57
m_SafeChar(i) = True
Next i
For i = 58 To 64
m_SafeChar(i) = False
Next i
For i = 65 To 90
m_SafeChar(i) = True
Next i
For i = 91 To 96
m_SafeChar(i) = False
Next i
For i = 97 To 122
m_SafeChar(i) = True
Next i
For i = 123 To 255
m_SafeChar(i) = False
Next i
End Sub
Thanks for helping me out.
-
Jan 16th, 2009, 06:08 AM
#8
Re: [RESOLVED] Replace chars
uh.. this is the PHP forum, not the VB forum. I'm not sure why you would be asking for help with Visual Basic here.
-
Jan 16th, 2009, 06:26 AM
#9
Thread Starter
Hyperactive Member
Re: [RESOLVED] Replace chars
because...i didn't know hot to get the %2B ecc chars...
Thanks for helping out anyway
Thanks for helping me out.
-
Jan 17th, 2009, 11:00 PM
#10
Re: [RESOLVED] Replace chars
Visual Basic questions go in the Visual Basic forum. I've moved this one.
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
|