Results 1 to 10 of 10

Thread: [RESOLVED] Replace chars

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    Resolved [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.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Replace chars

    uh.. you want to build a URL? then use url_encode(). that would only matter when using GET, not POST.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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.

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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.

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    353

    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.

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width