> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/u/url_encoding.md).

# URL encoding

```ruby
func urlencode(str) {
    str.gsub!(%r"([^-A-Za-z0-9_.!~*'() ])", {|a| "%%%02X" % a.ord })
    str.gsub!(' ', '+')
    return str
}
 
say urlencode('http://foo bar/')
```

#### Output:

```
http%3A%2F%2Ffoo+bar%2F
```
