---
url: >-
  /statelake/scripting-reference/functions-and-procedures/string-functions/urlencode.md
---

# URLEncode

**URLEncode** returns the string **Value** encoded for use within a URL.

This converts special characters, into URL acceptable characters.

This type of encoding is referred to as **Percent Encoding**, where the special characters are replaced in the string **Value** as their hexadecimal value, pre-fixed with a percent sign (%).

**Declaration**: Function URLEncode( Value : String) : String

In the below example, as URLs cannot contain spaces, URL encoding normally replaces a space with a %20 - a space in the file name is translated into ascii 32, which is hex 20. So it would appear as %20. However, a %20 can also be replaced with a plus (+) sign. A plus (+) sign and a %20 mean the same thing - it’s a space.

The index to the Str2 variable result -

* A space = %20 (or +)
* An apostrophe (') = %27
* An asterisk (\*) = %2A
* A shriek (!) = %21

```pascal
procedure OnMapEvent(var Value:Variant);
var
  Str1, Str2 : string;
begin
 //Returns 'The+File+Name.pdf'
  Str1 := URLEncode('The File Name.pdf');     //returns 'The%20File%20Name.pdf'
  LogInfo(Str1);

 //Returns 'The+Girl%27s+%2AParty%21.pdf'
  Str2 := URLEncode('The Girl''s *Party!.pdf');
  LogInfo(Str2);
  LogInfo('');

end;
```
