[#bsl-basic_string-01d-compare-0a]
= xref:bsl.adoc[bsl]::xref:bsl/basic_string-01d.adoc[basic&lowbar;string&lt;char8&lowbar;t&gt;]::compare
:relfileprefix: ../../
:mrdocs:

Lexicographically compare the substring of this string of the specified `lhsNumChars` length starting at the specified `lhsPosition` (or the suffix of this string starting at `lhsPosition` if `lhsPosition &plus; lhsNumChars &gt; length()`) with the substring of the specified `other` string of the optionally specified `otherNumChars` length starting at the specified `otherPosition` (or the suffix of `other` starting at `otherPosition` if `otherPosition &plus; otherNumChars &gt; other&period;length()`)&period; If `numChars` is not specified, `npos` is used&period; Return a negative value if the indicated substring of this string is less than the indicated substring of `other`, a positive value if it is greater than the indicated substring of `other`, and 0 in case of equality&period; `CHAR&lowbar;TRAITS&colon;&colon;lt` is used to compare characters&period; Throw `out&lowbar;of&lowbar;range` if `lhsPosition &gt; length()` or `otherPosition &gt; other&period;length()`&period; See &lcub;Lexicographical Comparisons&rcub;&period;

== Synopsis

Declared in `&lt;bslstl&lowbar;string&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
int
compare(
    xref:bsl/basic_string-01d/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-01d/size_type.adoc[size&lowbar;type] lhsNumChars,
    xref:bsl/basic_string-0faf.adoc[basic&lowbar;string&lt;char8&lowbar;t&gt;] const& other,
    xref:bsl/basic_string-01d/size_type.adoc[size&lowbar;type] otherPosition,
    xref:bsl/basic_string-01d/size_type.adoc[size&lowbar;type] otherNumChars = npos) const;
----


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