:relfileprefix: ../../../
[#boost-urls-url_base-set_encoded_fragment]

== xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/url_base.adoc[pass:[url_base]]::set_encoded_fragment


Set the fragment.


=== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url_base.hpp#L2522[boost/url/url_base.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
xref:boost/urls/url_base.adoc[url_base]&
set_encoded_fragment(xref:boost/urls/pct_string_view.adoc[pct_string_view] s);
----

=== Description


This function sets the fragment to the
specified string, which may contain
percent-escapes and which may be empty.
An empty fragment is distinct from
having no fragment.
Escapes in the string are preserved,
and reserved characters in the string
are percent-escaped in the result.
[,cpp]
----
assert( url("?first=john&last=doe" ).set_encoded_fragment( "john%2Ddoe" ).fragment() == "john-doe" );
----
[,cpp]
----
this->has_fragment() == true && this->fragment() == decode_view( s )
----

=== Linear in `this-&gt;size() + s.size()`.

=== Strong guarantee.

Calls to allocate may throw.
Exceptions thrown on invalid input.
[,cpp]
----
fragment    = *( pchar / "/" / "?" )
----

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-3.5[3.5.  Fragment]



=== Exceptions

|===
| Name | Thrown on

| ``s``
| 
contains an invalid percent-encoding.

|===



=== Parameters

|===
| Name | Description 

| *s*
| 
The string to set.

|===




=== See Also


xref:boost/urls/url_base/remove_fragment.adoc[remove_fragment]
,
xref:boost/urls/url_base/set_fragment.adoc[set_fragment]
.



