[#boost-urls-encode-04] = xref:boost/urls/encode-04.adoc[boost::urls::encode] :relfileprefix: ../../ :mrdocs: Return a percent‐encoded string == Synopsis Declared in `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/encode.hpp#L180[boost/url/encode.hpp]>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template< xref:boost/urls/string_token/StringToken.adoc[string_token::StringToken] StringToken = xref:boost/urls/string_token/return_string.adoc[string_token::return_string], xref:boost/urls/grammar/CharSet.adoc[grammar::CharSet] CS> StringToken::result_type encode( core::string_view s, CS const& allowed, xref:boost/urls/encoding_opts.adoc[encoding_opts] opt = {}, StringToken&& token = {}) noexcept; ---- == Description This function applies percent‐encoding to the string using the given options and character set, and returns the result as a string when called with default arguments. == 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. == Specification * https://datatracker.ietf.org/doc/html/rfc3986#section-2.1[] == Return Value The string == Parameters [cols=2] |=== | Name | Description | *s* | The string to encode. | *allowed* | The set of characters that is not percent‐encoded. | *opt* | The options for encoding. If this parameter is omitted, the default options are used. | *token* | A string token. |=== == See Also xref:boost/urls/encode-0d.adoc[`encode`], xref:boost/urls/encoded_size.adoc[`encoded_size`], xref:boost/urls/encoding_opts.adoc[`encoding_opts`], [.small]#Created with https://www.mrdocs.com[MrDocs]#