[#bsl-basic_string-0e-compare-0bc]
= xref:bsl.adoc[bsl]::xref:bsl/basic_string-0e.adoc[basic&lowbar;string&lt;wchar&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 specified null&hyphen;terminated `other` string (of length `CHAR&lowbar;TRAITS&colon;&colon;length(other)`), and return a negative value if the indicated substring of this string is less than `other`, a positive value if it is greater than `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()`&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-0e/size_type.adoc[size&lowbar;type] lhsPosition,
    xref:bsl/basic_string-0e/size_type.adoc[size&lowbar;type] lhsNumChars,
    wchar&lowbar;t const* other) const;
----


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