[#boost-urls-encode-04]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::encode
:relfileprefix: ../../
:mrdocs:

Return a percent&hyphen;encoded string

== Synopsis

Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/encode.hpp#Lundefined[boost&sol;url&sol;encode&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;
    xref:boost/urls/string_token/StringToken.adoc[string&lowbar;token::StringToken] StringToken = xref:boost/urls/string_token/return_string.adoc[string&lowbar;token::return&lowbar;string],
    xref:boost/urls/grammar/CharSet.adoc[grammar::CharSet] CS&gt;
StringToken::result&lowbar;type
encode(
    core::string&lowbar;view s,
    CS const& allowed,
    xref:boost/urls/encoding_opts.adoc[encoding&lowbar;opts] opt = &lcub;&rcub;,
    StringToken&& token = &lcub;&rcub;);
----

== Description

This function applies percent&hyphen;encoding to the string using the given options and character set, and returns the result as a string when called with default arguments&period;

== Example

[,cpp]
----
encoding_opts opt;
opt.space_as_plus = true;
std::string s = encode( "My Stuff", opt, pchars );

assert( s == "My+Stuff" );
----
== Exception Safety

Calls to allocate may throw&period;

== Specification

* https://datatracker.ietf.org/doc/html/rfc3986#section-2.1[2&period;1&period; Percent&hyphen;Encoding (rfc3986)]

== Return Value

The string

== Parameters

[cols="1,4"]
|===
|Name|Description

| *s*
| The string to encode&period;
| *allowed*
| The set of characters that is not percent&hyphen;encoded&period;
| *opt*
| The options for encoding&period; If this parameter is omitted, the default options are used&period;
| *token*
| A string token&period;
|===

== See Also

xref:boost/urls/encode-0d.adoc[`encode`], xref:boost/urls/encoded_size.adoc[`encoded&lowbar;size`], xref:boost/urls/encoding_opts.adoc[`encoding&lowbar;opts`],


[.small]#Created with https://www.mrdocs.com[MrDocs]#
