[#boost-urls-url_view_base-fragment]
= xref:boost/urls/url_view_base/fragment.adoc[boost::urls::url&lowbar;view&lowbar;base::fragment]
:relfileprefix: ../../../
:mrdocs:

Return the fragment

== Synopsis

Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/url_view_base.hpp#L2215[boost&sol;url&sol;url&lowbar;view&lowbar;base&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]&gt;
StringToken::result&lowbar;type
fragment(StringToken&& token = &lcub;&rcub;);
----

== Description

This function calculates the fragment of the url, with percent escapes decoded and without the leading pound sign (&apos;&num;&apos;) whose presence indicates that the url contains a fragment&period;

This function accepts an optional _StringToken_ parameter which controls the return type and behavior of the function&colon;

* When called with no arguments, the return type of the function is `std&colon;&colon;string`&period; Otherwise
* When called with a string token, the behavior and return type of the function depends on the type of string token being passed&period;

== Example
[,cpp]
----
assert( url_view( "http://www.example.com/index.htm#a%2D1" ).fragment() == "a-1" );
----
== Complexity
Linear in `this&hyphen;&gt;fragment()&period;size()`&period;

== Exception Safety
Calls to allocate may throw&period; String tokens may throw exceptions&period;

== BNF
[,cpp]
----
fragment        = *( pchar / "/" / "?" )

fragment-part   = [ "#" fragment ]
----
== Specification
* https://datatracker.ietf.org/doc/html/rfc3986#section-3.5[]

== Return Value

The fragment portion of the url&period;

== Parameters

[cols=2]
|===
| Name
| Description
| *token*
| An optional string token to use&period; If this parameter is omitted, the function returns a new `std&colon;&colon;string`&period;
|===

== See Also

xref:boost/urls/url_view_base/encoded_fragment.adoc[`encoded&lowbar;fragment`], xref:boost/urls/url_view_base/has_fragment.adoc[`has&lowbar;fragment`]&period;


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