[#boost-urls-url_base-set_encoded_fragment]
= xref:boost/urls/url_base/set_encoded_fragment.adoc[boost::urls::url&lowbar;base::set&lowbar;encoded&lowbar;fragment]
:relfileprefix: ../../../
:mrdocs:

Set the fragment&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/url_base.adoc[url&lowbar;base]&
set&lowbar;encoded&lowbar;fragment(xref:boost/urls/pct_string_view.adoc[pct&lowbar;string&lowbar;view] s);
----

== Description

This function sets the fragment to the specified string, which may contain percent&hyphen;escapes and which may be empty&period; An empty fragment is distinct from having no fragment&period; Escapes in the string are preserved, and reserved characters in the string are percent&hyphen;escaped in the result&period;

== Example
[,cpp]
----
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john%2Ddoe" ).fragment() == "john-doe" );
----
== Postconditions
[,cpp]
----
this->has_fragment() == true && this->fragment() == decode_view( s )
----
== Complexity
Linear in `this&hyphen;&gt;size() &plus; s&period;size()`&period;

== Exception Safety
Strong guarantee&period; Calls to allocate may throw&period; Exceptions thrown on invalid input&period;

== BNF
[,cpp]
----
fragment    = *( pchar / "/" / "?" )
----
== Specification
* https://datatracker.ietf.org/doc/html/rfc3986#section-3.5[]

== Exceptions

[cols=2]
|===
| Name
| Thrown on
| `system&lowbar;error`
| `s` contains an invalid percent&hyphen;encoding&period;
|===

== Return Value

* `&ast;this`
* `&ast;this`

== Parameters

[cols=2]
|===
| Name
| Description
| *s*
| The string to set&period;
|===

== See Also

xref:boost/urls/url_base/remove_fragment.adoc[`remove&lowbar;fragment`], xref:boost/urls/url_base/set_fragment.adoc[`set&lowbar;fragment`]&period;


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