Products:
News
Contact
German Website
Home Features Screenshots Videos Downloads Shop Knowledgebase


Search Knowledgebase:

 

Plugin: Escape certain characters

User question:

> I'm writing a plugin and need to escape certain characters in an

> URL. Is there a function available to escape characters?

 

No, there's no built in function available.

 

Here's a small function that you can use as starting point to escape certain characters:

 

 

Sub EscapeChars($s)
   Dim $i, $s2
   $s2 = ""
   For $i = 1 To Len($s)
      Dim $ch = GetChar($s, $i)
      If Pos(LCase($ch), "abcdefghijklmnopqrstuvwxyz0123456789%.") > 0 Then
         $s2 = $s2 + $ch
      Else
         $s2 = $s2 + "%" + IntToHex(Ord($ch), 2)
      End If
   Next
   Return $s2
End Sub

 

 

Usage:

 

$s = EscapeChars("http://www.domain.com/image.jpg")

 

Result:

 

$s = http%3A%2F%2Fwww.domain.com%2Fimage.jpg