[#boost-urls-static_url-set_fragment]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/static_url.adoc[static&lowbar;url]::set&lowbar;fragment
:relfileprefix: ../../../
:mrdocs:

Set the fragment&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/static_url.adoc[static&lowbar;url]&
set&lowbar;fragment(core::string&lowbar;view s);
----

== Description

This function sets the fragment to the specified string, which may be empty&period; An empty fragment is distinct from having no fragment&period; 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 doe" ).encoded_fragment() == "john%20doe" );
----
== Postconditions
[,cpp]
----
this->has_fragment() == true && this->fragment() == s
----
== Complexity
Linear in `this&hyphen;&gt;size() &plus; s&period;size()`&period;

== Exception Safety
Strong guarantee&period; Calls to allocate may throw&period;

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

== Return Value

`&ast;this`

== Parameters

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

== See Also

xref:boost/urls/static_url/remove_fragment.adoc[`remove&lowbar;fragment`], xref:boost/urls/static_url/set_encoded_fragment.adoc[`set&lowbar;encoded&lowbar;fragment`]&period;


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