VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



HTTPSafeString

by Greg Tyndall (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

Makes a string http querystring friendly by replacing all non-alpha and non-numeric characters with the appropriate hex code. Helpful when using the wininet API.
example: "(Find This)" becomes "%28Find%20This%29"

Inputs
Text as String
Code Returns
String

Rate HTTPSafeString

Public Function HTTPSafeString(Text As String) As String
  Dim lCounter As Long
  Dim sBuffer As String
  Dim sReturn As String
  
  sReturn = Text
  
  For lCounter = 1 To Len(Text)
    sBuffer = Mid(Text, lCounter, 1)
    If Not sBuffer Like "[a-z,A-Z,0-9]" Then
      sReturn = Replace(sReturn, sBuffer, "%" & Hex(Asc(sBuffer)))
    End If
  Next lCounter
  
  HTTPSafeString = sReturn
      
End Function

Download this snippet    Add to My Saved Code

HTTPSafeString Comments

No comments have been posted about HTTPSafeString. Why not be the first to post a comment about HTTPSafeString.

Post your comment

Subject:
Message:
0/1000 characters